Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
50
Task/CRC-32/FreeBASIC/crc-32.basic
Normal file
50
Task/CRC-32/FreeBASIC/crc-32.basic
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
' version 18-03-2017
|
||||
' compile with: fbc -s console
|
||||
|
||||
Function crc32(buf As String) As UInteger<32>
|
||||
|
||||
Static As UInteger<32> table(256)
|
||||
Static As UInteger<32> have_table
|
||||
Dim As UInteger<32> crc, k
|
||||
Dim As ULong i, j
|
||||
|
||||
If have_table = 0 Then
|
||||
For i = 0 To 255
|
||||
k = i
|
||||
For j = 0 To 7
|
||||
If (k And 1) Then
|
||||
k Shr= 1
|
||||
k Xor= &Hedb88320
|
||||
Else
|
||||
k Shr= 1
|
||||
End If
|
||||
table(i) = k
|
||||
Next
|
||||
Next
|
||||
have_table = 1
|
||||
End If
|
||||
|
||||
crc = Not crc ' crc = &Hffffffff
|
||||
|
||||
For i = 0 To Len(buf) -1
|
||||
crc = (crc Shr 8) Xor table((crc And &hff) Xor buf[i])
|
||||
Next
|
||||
|
||||
Return Not crc
|
||||
|
||||
End Function
|
||||
|
||||
' ------=< MAIN >=------
|
||||
|
||||
Dim As String l = "The quick brown fox jumps over the lazy dog"
|
||||
Dim As UInteger<32> crc
|
||||
|
||||
Print "input = "; l
|
||||
print
|
||||
Print "The CRC-32 checksum = "; Hex(crc32(l), 8)
|
||||
|
||||
' empty keyboard buffer
|
||||
While Inkey <> "" : Wend
|
||||
Print : Print "hit any key to end program"
|
||||
Sleep
|
||||
End
|
||||
Loading…
Add table
Add a link
Reference in a new issue