CRC-32: Difference between revisions
Content deleted Content added
Added PascalABC.NET |
|||
(2 intermediate revisions by 2 users not shown) | |||
Line 786:
{{out}}
<pre>CRC32 = 414FA339</pre>
=={{header|EasyLang}}==
<syntaxhighlight lang=text>
func crc32 buf$[] .
for i = 0 to 0xff
rem = i
for j to 8
if bitand rem 1 = 1
rem = bitxor bitshift rem -1 0xedb88320
else
rem = bitshift rem -1
.
.
table[] &= rem
.
crc = 0xffffffff
for c$ in buf$[]
c = strcode c$
crb = bitxor bitand crc 0xff c
crc = bitxor (bitshift crc -8) table[crb + 1]
.
return bitnot crc
.
s$ = "The quick brown fox jumps over the lazy dog"
print crc32 strchars s$
</syntaxhighlight>
{{out}}
<pre>
1095738169
</pre>
=={{header|Elixir}}==
Line 1,361 ⟶ 1,391:
bitwise_and(.; 255 ) as $crb
| bitwise_xor( $table[bitwise_xor($crb; $s[$i])] ; rightshift(8)) )
|
def task:
Line 1,906 ⟶ 1,934:
Output:
<pre>crc32 = 414FA339</pre>
=={{header|PascalABC.NET}}==
<syntaxhighlight lang="delphi">
type
TCrc32 = array[0..255] of longword;
function CreateCrcTable(): TCrc32;
begin
for var i: longword := 0 to 255 do
begin
var rem := i;
for var j := 0 to 7 do
if (rem and 1) > 0 then rem := (rem shr 1) xor $edb88320
else rem := rem shr 1;
result[i] := rem
end;
end;
const
Crc32Table = CreateCrcTable;
function Crc32(s: string): longword;
begin
result := $ffffffff;
foreach var c in s do
result := (result shr 8) xor Crc32Table[(result and $ff) xor byte(c)];
result := not result
end;
begin
writeln('crc32 = ', crc32('The quick brown fox jumps over the lazy dog').ToString('X'));
end.
</syntaxhighlight>
{{out}}
<pre>
crc32 = 414FA339
</pre>
=={{header|Perl}}==
|