I am struggling with the translation of the ElfHash() function from c to PB.
Here's the c code:
Now I know why I've always found excuses not to code in c: Too many cryptic operators!
Here's my best hack at a PB translation:
The PB code runs but it always returns zero.
Anyone have any suggestions?
Brad
------------------
Here's the c code:
Code:
unsigned long ElfHash(const unsigned char *key) { unsigned long h = 0; while (*key) { h = (h << 4) + *key++; unsigned long g = h & 0xF0000000L; if (g) h ^= g >> 24; h &= ~g; } return h; }
Here's my best hack at a PB translation:
Code:
Function ElfHash(sKey As String) As Long Local h As Long Local g As Long Local i As Long Local b As Byte Local lpsKey As Long Local lLen As Long h = 0 lpsKey = StrPtr(sKey) For i = 0 To Len(sKey) Shift Left h, 4 Incr lpsKey b = Peek(lpsKey) h = h + b g = h And &HF0000000& If IsTrue(g) Then Shift Right g, 24 h = h Xor g End If h = h And -g Next Function = h End Function Function PbMain() Print Str$(ElfHash("test")) End Function
Anyone have any suggestions?
Brad
------------------
Comment