CRC32 check with bmx?

BlitzMax Forums/BlitzMax Beginners Area/CRC32 check with bmx?

The Forum Archive is locked. These are the original blitzbasic.com forums, kept so their posts can still be read and searched. No new topics, replies or edits can be made here. To join the conversation, head over to the Blitz3D+ forums.

The code from the archive seems to need little modification??
Global crc_table[256]
crc_init()

Print Hex$(crc_string("ABC"))

End


Function crc_init()
  Local i
  Local j
  Local value

  For i=0 To 255
    value=i
    For j=0 To 7
      If (value & $1) Then 
        value=(value Shr 1) ~ $EDB88320
      Else
        value=(value Shr 1)
      EndIf
    Next
    crc_table[i]=value
  Next
End Function

Function crc_string(txt$)
  Local bbyte
  Local crc
  Local i
  Local size

  crc=$FFFFFFFF
  size=Len(txt$)
  For i=1 To size
    bbyte=Asc(Mid$(txt$,i,1))
    crc=(crc Shr 8) ~ crc_table[bbyte ~ (crc & $FF)]
  Next
  Return ~crc
End Function

Function crc_bank(bank)
  Local bbyte
  Local crc
  Local i
  Local size

  crc=$FFFFFFFF
  size=BankSize(bank)-1
  For i=0 To size
    bbyte=PeekByte(bank,i)
    crc=(crc Shr 8) ~ crc_table[bbyte ~ (crc & $FF)]
  Next
  Return ~crc
End Function

Function crc_file(name$)
  Local bbyte
  Local crc
  Local file:TStream

  crc=$FFFFFFFF
  file=ReadFile(name$)
  If file=Null Then Return
  While Not Eof(file)
    bbyte=ReadByte(file)
    crc=(crc Shr 8) ~ crc_table[bbyte ~ (crc & $FF)]
  Wend
  CloseFile file
  Return ~crc
End Function

NOTE: I've only changed things enough to get it running, I haven't fully maxerised the code.