2title = "2c: Bit Arithmetic"
11Computes the result of `2^a`, producing an atom.
51Produces an atom from a list `b` of length-value pairs `p` and `q`,
52where `p` is the length in blocks of size `a`, and `q` is an atomic
57`a` is a block size (see [`++bloq`](/docs/hoon/reference/stdlib/1c)).
59`b` is a `list` of length-value pairs, `p` and `q`.
70 |= [a=bloq b=(list [p=@ q=@])]
73 (add (end a p.i.b q.i.b) (lsh a p.i.b $(b t.b)))
79 > `@ub`21 :: @ub is the binary aura
82 > `@ub`(can 3 ~[[1 21]])
85 > `@ub`(can 3 ~[[1 1]])
88 > `@ub`(can 0 ~[[1 255]])
91 > `@ux`(can 3 [3 0xc1] [1 0xa] ~) :: @ux is the hexadecimal aura
94 > `@ux`(can 3 [3 0xc1] [1 0xa] [1 0x23] ~)
97 > `@ux`(can 4 [3 0xc1] [1 0xa] [1 0x23] ~)
98 0x23.000a.0000.0000.00c1
100 > `@ux`(can 3 ~[[1 'a'] [2 'bc']])
110Concatenates two atoms, `b` and `c`, according to block size `a`, producing an
115`a` is a block size (see [`++bloq`](/docs/hoon/reference/stdlib/1c)).
131 (add (lsh a (met a b) c) b)
137 > `@ub`(cat 3 1 0) :: @ub is the binary aura
155 > `@ub`(cat 3 256 255)
156 0b1111.1111.0000.0001.0000.0000
158 > `@ub`(cat 2 256 255)
159 0b1111.1111.0001.0000.0000
174Slices `c` blocks of size `a` that are positioned `b` blocks from the end of
175`d`. That slice is produced as an atom.
179`a` is a block size (see [`++bloq`](/docs/hoon/reference/stdlib/1c)).
196 |= [a=bloq [b=@u c=@u] d=@]
197 (end a c (rsh a b d))
209 > `@t`(cut 3 [0 3] 'abcdefgh')
212 > `@t`(cut 3 [1 3] 'abcdefgh') :: @t is the cord aura
215 > `@ub`(cut 0 [0 3] 0b1111.0000.1101) :: @ub is the binary aura
218 > `@ub`(cut 0 [0 6] 0b1111.0000.1101)
221 > `@ub`(cut 0 [4 6] 0b1111.0000.1101)
224 > `@ub`(cut 0 [3 6] 0b1111.0000.1101)
234Produces an atom by taking the last `step` blocks of size `bloq` from `b`.
238`a` is an atom slice specifier (see [`++bite`](/docs/hoon/reference/stdlib/1c#bite)),
239which is a block size (see [`++bloq`](/docs/hoon/reference/stdlib/1c#bloq))
240with optional block count.
254 =/ [=bloq =step] ?^(a a [a *step])
255 (mod b (bex (mul (bex bloq) step)))
273 > `@ub`12 :: @ub is the binary aura
276 > `@ub`(end [0 3] 12)
282 > `@ub`(end [1 3] 12)
288 > `@ux`'abc' :: @ux is the hexademical aura
291 > `@ux`(end [3 2] 'abc')
294 > `@t`(end [3 2] 'abc') :: @t is the cord aura
304Produces an atom by repeating `c` for `b` blocks of size `a`.
308`a` is a block size (see [`++bloq`](/docs/hoon/reference/stdlib/1c)).
328 $(d (add c (lsh a 1 d)), n +(n))
334 > `@t`(fil 3 5 %a) :: @t is the cord (string) aura
337 > `@t`(fil 5 10 %ceeb)
338 'ceebceebceebceebceebceebceebceebceebceeb'
340 > `@t`(fil 4 10 %eced)
343 > `@tas`(fil 4 10 %bf) :: @tas is the term aura
344 %bfbfbfbfbfbfbfbfbfbf
346 > `@ub`(fil 2 6 1) :: @ub is the binary aura
347 0b1.0001.0001.0001.0001.0001
356Produces an atom by left-shifting `b` by `step` blocks of size `bloq`.
360`a` is an atom slice specifier (see [`++bite`](/docs/hoon/reference/stdlib/1c#bite)),
361which is a block size (see [`++bloq`](/docs/hoon/reference/stdlib/1c#bloq))
362with optional block count.
376 =/ [=bloq =step] ?^(a a [a *step])
377 (mul b (bex (mul (bex bloq) step)))
383 > `@ub`1 :: @ub is the binary aura
398 > `@ub`(lsh [3 1] 255)
399 0b1111.1111.0000.0000
411Computes the number of blocks of size `a` in `b`, producing an atom.
415`a` is a block size (see [`++bloq`](/docs/hoon/reference/stdlib/1c)).
429 $(b (rsh a 1 b), c +(c))
457Concatenates a list of atoms `b` using block size `a`, producing an atom.
461`a` is a block size (see [`++bloq`](/docs/hoon/reference/stdlib/1c)).
463`b` is a `list` of atoms.
474 |= [a=bloq b=(list @)]
484 > `@ub`(rap 2 [1 2 3 4 ~]) :: @ub is the binary aura
487 > `@ub`(rap 1 [1 2 3 4 ~])
499 > (rap 0 [0 1 0 0 1 2 ~])
511Any element of the value `0` is not included in concatenation.
519Produces an atom by assembling a list of atoms `b` using block size `a`.
523`a` is an atom slice specifier (see [`$bite`](/docs/hoon/reference/stdlib/1c#bite)),
524which is a block size (see [`$bloq`](/docs/hoon/reference/stdlib/1c#bloq))
525with optional block count.
527`b` is a list of atoms.
538 |= [a=bite b=(list @)]
539 =/ [=bloq =step] ?^(a a [a *step])
543 %+ add $(i +(i), b t.b)
544 (lsh [bloq (mul step i)] (end [bloq step] i.b))
550 > `@ub`(rep 2 [1 2 3 4 ~]) :: @ub is the binary aura
556 > (rep 0 [0 0 0 1 ~])
559 > `@ub`(rep 0 [0 0 0 1 ~])
565 > `@ub`(rep 0 [1 0 1 0 ~])
568 > `@ub`(rep 0 [1 2 3 4 ~])
571 > (rep 0 [0 1 0 1 ~])
574 > (rep 0 [1 0 1 0 1 ~])
580 > `@ub`(rep 3 [12 166 8 34 ~])
581 0b10.0010.0000.1000.1010.0110.0000.1100
586 > `@t`(rep 3 "abcd") :: @t is the text aura
594Reverses block order, accounting for leading zeroes.
596Produces an atom from the bits of `dat` in reverse order according to a block
597size `boz` and a size `len`.
599If the total size is less than the length of `dat`, then only the first
600bits of `dat` up to the total size will be taken and reversed. If the total size
601is longer, trailing zeroes will be added.
605`boz` is a block size with optional block count (see
606[`$bloq`](/docs/hoon/reference/stdlib/1c#bloq)).
608`len` is a `@ud` of the number of blocks of size `boz` to be reversed.
621 |= [boz=bloq len=@ud dat=@]
623 =. dat (end [boz len] dat)
625 [boz (sub len (met boz dat))]
632> =a 0b1111.0000.1111.1010.0011
6350b1100.0101.1111.0000.1111
6410b11.1010.1111.0000.1111
6470b11.1010.1111.0000.1111.0000
665Produces a list of atoms from the bits of `b` using block size `a`.
669`a` is an atom slice specifier (see [`$bite`](/docs/hoon/reference/stdlib/1c#bite)),
670which is a block size (see [`$bloq`](/docs/hoon/reference/stdlib/1c#bloq))
671with optional block count.
687 [(end a b) $(b (rsh a b))]
693 > `@ub`155 :: @ub is the binary aura
720 > `tape`(rip 3 'abcd')
730Right-shifts `b` by `step` blocks of size `bloq`, producing an atom.
734`a` is an atom slice specifier (see [`$bite`](/docs/hoon/reference/stdlib/1c#bite)),
735which is a block size (see [`$bloq`](/docs/hoon/reference/stdlib/1c#bloq))
736with optional block count.
750 =/ [=bloq =step] ?^(a a [a *step])
751 (div b (bex (mul (bex bloq) step)))
757 > `@ub`145 :: @ub is the binary aura
760 > `@ub`(rsh [1 1] 145)
769 > `@ub`(rsh [2 1] 145)
778 > `@ub`(rsh [0 1] 10)
787 > `@t`(rsh [3 1] 'abc')
790 > `@ux`(rsh [3 1] 'abc')
800Disassembles atom `b` into slices specified by `a`, applies `c` to each slice,
801and reassembles the results back into an atom.
805`a` is an atom slice specifier (see [`$bite`](/docs/hoon/reference/stdlib/1c#bite)),
806which is a block size (see [`$bloq`](/docs/hoon/reference/stdlib/1c#bloq))
807with optional block count.
811`c` is a gate that accepts an atom and produces an atom.
822 |= [a=bite b=@ c=$-(@ @)]
823 (rep a (turn (rip a b) c))
829 > `@ux`65.535 :: @ux is the hexadecimal aura
832 > `@ux`(run 2 65.535 dec) :: dec is the decrement gate
842Disassembles atom `b` into slices specified by `a`, applies `c` to each slice,
843and assembles the results back into a.
847`a` is an atom slice specifier (see [`$bite`](/docs/hoon/reference/stdlib/1c#bite)),
848which is a block size (see [`$bloq`](/docs/hoon/reference/stdlib/1c#bloq))
849with optional block count.
853`c` is a gate that accepts an atom.
864 |* [a=bite b=@ c=$-(@ *)]
871 > `@ux`65.535 :: @ux is the hexadecimal aura
874 > `(list @ux)`(rut 2 65.535 dec) :: dec is the decrement gate
884Switches little-endian to big-endian and vice versa: produces an atom by
885reversing the block order of `b` using block size `a`.
889`a` is a block size (see [`++bloq`](/docs/hoon/reference/stdlib/1c)).
900 ++ swp |=([a=bloq b=@] (rep a (flop (rip a b))))
906 > `@ub`24 :: @ub is the binary aura
928Computes the base-2 logarithm of `a`, producing an atom.
976Core that contains arms for `bloq` and modular integer operations.
992Produces the difference between two atoms in the modular basis
1010 ++ dif |=([b=@ c=@] (sit (sub (add out (sit b)) (sit c))))
1016 > (~(dif fe 3) 63 64)
1019 > (~(dif fe 3) 5 10)
1025 > (~(dif fe 0) 9 10)
1028 > (~(dif fe 0) 9 11)
1031 > (~(dif fe 0) 9 12)
1034 > (~(dif fe 2) 9 12)
1037 > (~(dif fe 2) 63 64)
1047Inverts the order of the modular field.
1051`b` is a `bloq`. (see [`++bloq`](/docs/hoon/reference/stdlib/1c))
1060 ++ inv |=(b=@ (sub (dec out) (sit b)))
1091Reverses bytes within a block.
1095`b` is a `bloq`. (see [`++bloq`](/docs/hoon/reference/stdlib/1c))
1110 (lsh c 1 $(a c, b (cut c [0 1] b)))
1111 $(a c, b (cut c [1 1] b))
1160 72.057.594.037.927.936
1163 144.115.188.075.855.872
1166 216.172.782.113.783.808
1169 288.230.376.151.711.744
1172 360.287.970.189.639.680
1181Produces the maximum integer value that the current block can store; `2^a^a`.
1194 ++ out (bex (bex a))
1216 \/179.769.313.486.231.590.772.930.519.078.902.473.361.797.697.894.230.657.273\/
1217 .430.081.157.732.675.805.500.963.132.708.477.322.407.536.021.120.113.879.87
1218 1.393.357.658.789.768.814.416.622.492.847.430.639.474.124.377.767.893.424.8
1219 65.485.276.302.219.601.246.094.119.453.082.952.085.005.768.838.150.682.342.
1220 462.881.473.913.110.540.827.237.163.350.510.684.586.298.239.947.245.938.479
1221 .716.304.835.356.329.624.224.137.216
1231Rolls `d` to the left by `c` `b`-sized blocks.
1250 ++ rol |= [b=bloq c=@ d=@] ^- @
1252 =+ f=(bex (sub a b))
1254 (sit (con (lsh b g e) (rsh b (sub f g) e)))
1260 > `@ux`(~(rol fe 6) 4 3 0xabac.dedf.1213)
1261 0x1213.0000.abac.dedf
1263 > `@ux`(~(rol fe 6) 4 2 0xabac.dedf.1213)
1264 0xdedf.1213.0000.abac
1266 > `@t`(~(rol fe 5) 3 1 'dfgh')
1269 > `@t`(~(rol fe 5) 3 2 'dfgh')
1272 > `@t`(~(rol fe 5) 3 0 'dfgh')
1282Rolls `d` to the right by `c` `b`-sized blocks.
1301 ++ ror |= [b=bloq c=@ d=@] ^- @
1303 =+ f=(bex (sub a b))
1305 (sit (con (rsh b g e) (lsh b (sub f g) e)))
1311 > `@ux`(~(ror fe 6) 4 1 0xabac.dedf.1213)
1312 0x1213.0000.abac.dedf
1314 > `@ux`(~(ror fe 6) 3 5 0xabac.dedf.1213)
1315 0xacde.df12.1300.00ab
1317 > `@ux`(~(ror fe 6) 3 3 0xabac.dedf.1213)
1318 0xdf12.1300.00ab.acde
1320 > `@t`(~(rol fe 5) 3 0 'hijk')
1323 > `@t`(~(rol fe 5) 3 1 'hijk')
1326 > `@t`(~(rol fe 5) 3 2 'hijk')
1336Produces an atom in the current modular block representation.
1351 ++ sit |=(b=@ (end a 1 b))
1369 > (~(sit fe 2) 10.000)
1397Sums two numbers in this modular field.
1414 ++ sum |=([b=@ c=@] (sit (add b c)))
1420 > (~(sum fe 3) 10 250)
1429 > (~(sum fe 2) 14 2)
1432 > (~(sum fe 2) 14 3)
1435 > (~(sum fe 4) 10.000 256)
1438 > (~(sum fe 4) 10.000 100.000)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list