Hash Code Help
Bill Drummond
Posts: 54
I trying to port this pascal code to Spin
This doesn't work..
function ELFHash(const Str : String) : Int64; var i : integer; x : Cardinal; begin Result := 0; for i := 1 to Length(Str) do begin Result := (Result shl 4) + Ord(Str[noparse][[/noparse]i]); x := Result and $F0000000; if (x <> 0) then begin Result := Result xor (x shr 24); end; Result := Result and (not x); end; end;
This doesn't work..
''*************************************** ''* From Keyboard Demo v1.0 * ''* Author: Chip Gracey * ''* Copyright (c) 2006 Parallax, Inc. * ''* See end of file for terms of use. * ''***************************************
CON
_clkmode = xtal1 + pll16x _xinfreq = 5_000_000
VAR byte j long x OBJ
term : "tv_terminal" kb : "keyboard"
PUB start | i
'start the tv terminal term.start(12) term.str(string("HashCode Demo...",13))
'start the keyboard kb.start(26, 27) term.Hex(Hash(String("DIR")),8) term.out(13) term.Hex(Hash(String("TYPE")),8) term.out(13) term.Hex(Hash(String("MOUNT")),8) term.out(13) term.Hex(Hash(String("UNMOUNT")),8) term.out(13) PUB Hash(string_ptr) : Result result := 0 repeat strsize(string_ptr) Result := (Result << 4) + byte[noparse][[/noparse]string_ptr++] x := Result and $F0_00_00_00 if (x <> 0) Result := Result ^ (x >> 24) Result := result & (not x) {{
Here is a windows program
zip
202K
Comments
into that (bitwise AND)
any idea why it breaks with more than 6 characters?
Post Edited (Bill Drummond) : 4/3/2009 10:08:26 AM GMT
Post Edited (kuroneko) : 4/3/2009 10:17:26 AM GMT
I edited the Windows program so everybody uses hex.
And I'm also not too comfortable with repeat strsize(). Is this evaluated only at the beginning of the loop or everytime the loop is run? If you put some debug tracing in there, how far does it get?
same result. That's true, but I changed it to Cardinal(unsigned 32 bit)·and it still works.
I need to Learn how ViewPort works... got too many projects going at same time.
Change...
...which is a boolean 'NOT' to...
...which is a bitwise 'NOT'.
If I key in : 1234567·· · I see $00000000 should be $045678A7
If I key in : 123456789 I see $000003B9 should be $0678AEE9
If I key in :·MOUNT····· I see $00524A34··- is good
If I key in : UNMOUNT· I see $00000000 should be $0A324A64
Download the File in my first post to run the Hash Code generator on a PC.
··