interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / drafts / rosettacode / crc-32.wiki

58 lines · 1118 bytes Raw Blame History
1=={{header|Omegese}}==
2{{works with|omc|sha256 2c824805, aien-dev/omega-mv e5b32567, Linux AArch64}}
3Omega has no imports, so the small output helpers (<code>emit</code> and friends) are part of the program.
4<syntaxhighlight lang="text">
5om2
6text nl "\n"
7text msg "The quick brown fox jumps over the lazy dog"
8note emit writes every byte of a to stdout; a short write is retried, an error exits 1
9fn emit a view uchar * to void
10o = ulong 0
11while lt o len a bound 4096
12k = write 1 a o sub len a o
13if le k 0
14exit 1
15end
16o = add o ulong k
17end
18end
19note emitx writes n as 8 lowercase hex digits
20fn emitx n uint to void
21d = new uchar 8 0
22v = n
23for i ulong 8
24q = uchar and v 15
25if lt q 10
26put d sub 7 i add q 48
27else
28put d sub 7 i add q 87
29end
30v = shr v 4
31end
32emit d
33end
34note bitwise reflected CRC-32 (polynomial 0xedb88320), no table
35fn crc32 a view uchar * to uint
36c = uint 0xffffffff
37for i ulong len a
38c = xor c uint get a i
39for k ulong 8
40if eq and c 1 1
41c = xor shr c 1 0xedb88320
42else
43c = shr c 1
44end
45end
46end
47ret not c
48end
49fn main to int
50emitx crc32 msg
51emit nl
52ret 0
53end
54</syntaxhighlight>
55{{out}}
56<pre>
57414fa339
58</pre>