interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / tasks / binary-digits / binary-digits.om

38 lines · 665 bytes Raw Blame History
1note Rosetta Code task "Binary digits": https://rosettacode.org/wiki/Binary_digits
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5note emit writes every byte of a to stdout; a short write is retried, an error exits 1
6fn emit a view uchar * to void
7o = ulong 0
8while lt o len a bound 4096
9k = write 1 a o sub len a o
10if le k 0
11exit 1
12end
13o = add o ulong k
14end
15end
16fn bin n ulong to void
17d = new uchar 64 0
18i = ulong 64
19v = n
20while true bound 64
21i = sub i 1
22put d i uchar add and v 1 48
23v = shr v 1
24if eq v 0
25break
26end
27end
28emit part d i sub 64 i
29emit nl
30end
31fn main to int
32bin 0
33bin 5
34bin 50
35bin 9000
36bin 18446744073709551615
37ret 0
38end