ok I'm attempting to implement a basic crc32 algorithm that I have the
original in VB and need to implement it in c#.
I appear to be running into an issue with the hex values when doing the bit
shifting. Anyways here is one of the functions in VB. This one builds a
polynomial table incase anyone cares.
'Public function to build polynomial table (don't touch!!)
Public Function InitCrc32(Optional ByVal Seed As Long = &HEDB88320, Optional
ByVal Precondition As Long = &HFFFFFFFF) As Long
'Declare counters
Dim iBytes As Integer, iBits As Integer, lCrc32 As Long, lTempCrc32 As Long
On Error Resume Next
For iBytes = 0 To 255
lCrc32 = iBytes
For iBits = 0 To 7
'Right shift unsigned long 1 bit
lTempCrc32 = lCrc32 And &HFFFFFFFE
lTempCrc32 = lTempCrc32 \ &H2
lTempCrc32 = lTempCrc32 And &H7FFFFFFF
'Now check if temporary is less than zero and then mix Crc32 checksum with
Seed value
If (lCrc32 And &H1) <> 0 Then
lCrc32 = lTempCrc32 Xor Seed
Else
lCrc32 = lTempCrc32
End If
Next
'Put Crc32 checksum value in the holding array
Crc32Table(iBytes) = lCrc32
Next
'After this is done, set function value to the precondition value
InitCrc32 = Precondition
End Function
And here is what I translated it into. Some of the variable names have
been changed.
public long initCRC32()
{
long seed = 0xEDB88320;
long precondition = 0xFFFFFFFF;
int bytes;
int bits;
long crc32;
long tempCrc32;
for (bytes = 0; bytes<255;bytes++)
{
crc32 = bytes;
for (bits = 0; bits < 8; bits++)
{
tempCrc32 = crc32 & 0xFFFFFFFE;
tempCrc32 = tempCrc32 / 0x2;
tempCrc32 = tempCrc32 & 0x7FFFFFFF;
if((crc32 & 0x1) != 0)
{
crc32 = tempCrc32 ^ seed;
}
else
{
crc32 = tempCrc32;
}
}
ccitt_32[bytes] = crc32;
}
return (precondition);
}
It runs but the values going into the table don't match. Walking through
the debugger with a watch on the seed variable right away it is different so
it's not a logic issue that I can see it's gotta be syntax .Anyone have any
idea on what I'm doing wrong?