47 lines
910 B
Plaintext
47 lines
910 B
Plaintext
//
|
|
// CRC_32 Checksum
|
|
//
|
|
// FutureBasic 7.0.34, August 2025 R.W
|
|
//----------------------------------------------
|
|
|
|
// Get CRC_32 checksum from a CFstring
|
|
// using the standard bits reversed 0x04C11DB7
|
|
|
|
// Verified accuracy using the site
|
|
// https://codeshack.io/crc32-checksum-generator/
|
|
|
|
local fn getCRC_32 (textStr As CFStringRef) As UInt32
|
|
UInt32 i, j, crc, byte
|
|
crc = 0xFFFFFFFF
|
|
|
|
for i = 0 to len(textStr) -1
|
|
byte = ucc(textStr, i)
|
|
crc = crc XOR byte
|
|
for j = 0 to 7
|
|
if ( crc AND 1 )
|
|
crc = (crc >> 1) XOR 0xEDB88320
|
|
else
|
|
crc = crc >> 1
|
|
end if
|
|
next
|
|
next
|
|
crc = crc XOR 0xFFFFFFFF
|
|
end fn = crc
|
|
|
|
|
|
window 1,@"CRC checksum"
|
|
|
|
CFStringRef testString
|
|
testString = @"The quick brown fox jumps over the lazy dog"
|
|
|
|
UInt32 checksum
|
|
checksum = fn getCRC_32(testString)
|
|
|
|
print
|
|
print @" ";testString
|
|
print @" has a checksum of ";hex(checksum)
|
|
|
|
handleEvents
|
|
|
|
//
|