interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / tasks / crc-32 / crc-32.om

51 lines · 961 bytes Raw Blame History
1note Rosetta Code task "CRC-32": https://rosettacode.org/wiki/CRC-32
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text msg "The quick brown fox jumps over the lazy dog"
6note emit writes every byte of a to stdout; a short write is retried, an error exits 1
7fn emit a view uchar * to void
8o = ulong 0
9while lt o len a bound 4096
10k = write 1 a o sub len a o
11if le k 0
12exit 1
13end
14o = add o ulong k
15end
16end
17note emitx writes n as 8 lowercase hex digits
18fn emitx n uint to void
19d = new uchar 8 0
20v = n
21for i ulong 8
22q = uchar and v 15
23if lt q 10
24put d sub 7 i add q 48
25else
26put d sub 7 i add q 87
27end
28v = shr v 4
29end
30emit d
31end
32note bitwise reflected CRC-32 (polynomial 0xedb88320), no table
33fn crc32 a view uchar * to uint
34c = uint 0xffffffff
35for i ulong len a
36c = xor c uint get a i
37for k ulong 8
38if eq and c 1 1
39c = xor shr c 1 0xedb88320
40else
41c = shr c 1
42end
43end
44end
45ret not c
46end
47fn main to int
48emitx crc32 msg
49emit nl
50ret 0
51end