CRC-32: Difference between revisions

1,761 bytes added ,  2 months ago
m
→‎{{header|11l}}: `(-)` -> `~`
(→‎{{header|PARI/GP}}: append Free Pascal . CRC is the unit to use. ala https://forum.lazarus.freepascal.org/index.php/topic,36396.msg242520.html)
m (→‎{{header|11l}}: `(-)` -> `~`)
(5 intermediate revisions by 4 users not shown)
Line 33:
 
F crc32(buf, =crc = UInt32(0))
crc = (-)~crc
L(k) buf
crc = (crc >> 8) (+) :crc_table[(crc [&] F'F) (+) k.code]
R (-)~crc
 
print(hex(crc32(‘The quick brown fox jumps over the lazy dog’)))</syntaxhighlight>
Line 388:
{{out}}
<pre>0x414fa339</pre>
 
=={{header|Bait}}==
<syntaxhighlight lang="bait">
import hash.crc32
 
fun main() {
text := 'The quick brown fox jumps over the lazy dog'
sum := crc32.checksum(text.bytes())
println(sum.hex())
}
</syntaxhighlight>
 
{{out}}
<pre>
414fa339
</pre>
 
=={{header|C}}==
Line 2,398 ⟶ 2,414:
 
hex CRC-32 checksum = D1370232 dec CRC-32 checksum = 3510043186
</pre>
 
=={{header|RPL}}==
{{trans|FreeBASIC}}
≪ → string
≪ <span style="color:red">32</span> STWS <span style="color:grey">@ set binary word size to 32</span>
'''IFERR''' ‘<span style="color:green">CRCtable</span>’ RCL '''THEN'''
{ }
<span style="color:red">0 255</span> '''FOR''' j
j R→B
<span style="color:red">0 7</span> '''START'''
SR '''IF''' LAST <span style="color:red">#1</span> AND B→R '''THEN''' <span style="color:red">#EDB88320h</span> XOR '''END'''
'''NEXT''' + '''NEXT'''
‘<span style="color:green">CRCtable</span>’ STO
'''END'''
DROP <span style="color:red">#0</span> NOT
<span style="color:red">1</span> string SIZE '''FOR''' j
SRB SWAP
<span style="color:red">#FFh</span> AND string j DUP SUB NUM R→B XOR
B→R <span style="color:red">1</span> + ‘<span style="color:green">CRCtable</span>’ SWAP GET XOR
'''NEXT'''
NOT
≫ ≫ ‘<span style="color:blue">CRC32</span>’ STO
 
<span style="color:red">"The quick brown fox jumps over the lazy dog"</span> <span style="color:blue">CRC32</span>
{{out}}
<pre>
1: # 414FA339h
</pre>
 
Line 2,969 ⟶ 3,013:
{{trans|Go}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang=ecmascript"wren">import "./fmt" for Conv
 
class CRC32 {
Line 3,038 ⟶ 3,082:
ZLib.calcCRC32(Data(Void,"The quick brown fox jumps over the lazy dog"));
//-->0x414fa339</syntaxhighlight>
 
=={{header|Zig}}==
<syntaxhighlight lang="zig">const std = @import("std");
const Crc32Ieee = std.hash.Crc32;
 
pub fn main() !void {
var res: u32 = Crc32Ieee.hash("The quick brown fox jumps over the lazy dog");
std.debug.print("{x}\n", .{res});
}
</syntaxhighlight>
 
{{out}}
<pre>
414fa339
</pre>
1,481

edits