(phixonline)-->
with javascript_semantics
sequence table
bool have_table = false
function crc32(string s)
if not have_table then
have_table = true
table = repeat(0,256)
for i=0 to 255 do
atom rem = i
for j=1 to 8 do
if and_bits(rem,1) then
rem = xor_bits(floor(rem/2),#EDB88320)
else
rem = floor(rem/2)
end if
if rem<0 then
rem += #100000000
end if
end for
table[i+1] = rem
end for
end if
atom crc = #FFFFFFFF
for i=1 to length(s) do
crc = xor_bits(floor(crc/#100),table[xor_bits(and_bits(crc,0xff),s[i])+1])
if crc<0 then
crc += #100000000
end if
end for
return and_bits(not_bits(crc),#FFFFFFFF)
end function
string s = "The quick brown fox jumps over the lazy dog"
printf(1,"The CRC of %s is %08x\n",{s,crc32(s)})