2title = "2c: Bit Arithmetic"
11Computes the result of `2^a`, producing an atom.
50Produces an atom from a list `b` of length-value pairs `p` and `q`,
51where `p` is the length in blocks of size `a`, and `q` is an atomic
56`a` is a block size (see [`++bloq`](@/docs/hoon/reference/stdlib/1c.md)).
58`b` is a `list` of length-value pairs, `p` and `q`.
69 |= [a=bloq b=(list [p=@ q=@])]
72 (add (end a p.i.b q.i.b) (lsh a p.i.b $(b t.b)))
78 > `@ub`21 :: @ub is the binary aura
81 > `@ub`(can 3 ~[[1 21]])
84 > `@ub`(can 3 ~[[1 1]])
87 > `@ub`(can 0 ~[[1 255]])
90 > `@ux`(can 3 [3 0xc1] [1 0xa] ~) :: @ux is the hexadecimal aura
93 > `@ux`(can 3 [3 0xc1] [1 0xa] [1 0x23] ~)
96 > `@ux`(can 4 [3 0xc1] [1 0xa] [1 0x23] ~)
97 0x23.000a.0000.0000.00c1
99 > `@ux`(can 3 ~[[1 'a'] [2 'bc']])
108Concatenates two atoms, `b` and `c`, according to block size `a`, producing an
113`a` is a block size (see [`++bloq`](@/docs/hoon/reference/stdlib/1c.md)).
129 (add (lsh a (met a b) c) b)
135 > `@ub`(cat 3 1 0) :: @ub is the binary aura
153 > `@ub`(cat 3 256 255)
154 0b1111.1111.0000.0001.0000.0000
156 > `@ub`(cat 2 256 255)
157 0b1111.1111.0001.0000.0000
171Slices `c` blocks of size `a` that are positioned `b` blocks from the end of
172`d`. That slice is produced as an atom.
176`a` is a block size (see [`++bloq`](@/docs/hoon/reference/stdlib/1c.md)).
193 |= [a=bloq [b=@u c=@u] d=@]
194 (end a c (rsh a b d))
206 > `@t`(cut 3 [0 3] 'abcdefgh')
209 > `@t`(cut 3 [1 3] 'abcdefgh') :: @t is the cord aura
212 > `@ub`(cut 0 [0 3] 0b1111.0000.1101) :: @ub is the binary aura
215 > `@ub`(cut 0 [0 6] 0b1111.0000.1101)
218 > `@ub`(cut 0 [4 6] 0b1111.0000.1101)
221 > `@ub`(cut 0 [3 6] 0b1111.0000.1101)
231Produces an atom by taking the last `step` blocks of size `bloq` from `b`.
235`a` is an atom slice specifier (see [`++bite`](@/docs/hoon/reference/stdlib/1c.md#bite)),
236which is a block size (see [`++bloq`](@/docs/hoon/reference/stdlib/1c.md#bloq))
237with optional block count.
252 =/ [=bloq =step] ?^(a a [a *step])
253 (mod b (bex (mul (bex bloq) step)))
271 > `@ub`12 :: @ub is the binary aura
274 > `@ub`(end [0 3] 12)
280 > `@ub`(end [1 3] 12)
286 > `@ux`'abc' :: @ux is the hexademical aura
289 > `@ux`(end [3 2] 'abc')
292 > `@t`(end [3 2] 'abc') :: @t is the cord aura
302Produces an atom by repeating `c` for `b` blocks of size `a`.
306`a` is a block size (see [`++bloq`](@/docs/hoon/reference/stdlib/1c.md)).
326 $(d (add c (lsh a 1 d)), n +(n))
332 > `@t`(fil 3 5 %a) :: @t is the cord (string) aura
335 > `@t`(fil 5 10 %ceeb)
336 'ceebceebceebceebceebceebceebceebceebceeb'
338 > `@t`(fil 4 10 %eced)
341 > `@tas`(fil 4 10 %bf) :: @tas is the term aura
342 %bfbfbfbfbfbfbfbfbfbf
344 > `@ub`(fil 2 6 1) :: @ub is the binary aura
345 0b1.0001.0001.0001.0001.0001
354Produces an atom by left-shifting `b` by `step` blocks of size `bloq`.
358`a` is an atom slice specifier (see [`++bite`](@/docs/hoon/reference/stdlib/1c.md#bite)),
359which is a block size (see [`++bloq`](@/docs/hoon/reference/stdlib/1c.md#bloq))
360with optional block count.
374 =/ [=bloq =step] ?^(a a [a *step])
375 (mul b (bex (mul (bex bloq) step)))
381 > `@ub`1 :: @ub is the binary aura
396 > `@ub`(lsh [3 1] 255)
397 0b1111.1111.0000.0000
409Computes the number of blocks of size `a` in `b`, producing an atom.
413`a` is a block size (see [`++bloq`](@/docs/hoon/reference/stdlib/1c.md)).
427 $(b (rsh a 1 b), c +(c))
455Concatenates a list of atoms `b` using block size `a`, producing an atom.
459`a` is a block size (see [`++bloq`](@/docs/hoon/reference/stdlib/1c.md)).
461`b` is a `list` of atoms.
472 |= [a=bloq b=(list @)]
482 > `@ub`(rap 2 [1 2 3 4 ~]) :: @ub is the binary aura
485 > `@ub`(rap 1 [1 2 3 4 ~])
497 > (rap 0 [0 1 0 0 1 2 ~])
509Any element of the value `0` is not included in concatenation.
516Produces an atom by assembling a list of atoms `b` using block size `a`.
520`a` is an atom slice specifier (see [`$bite`](@/docs/hoon/reference/stdlib/1c.md#bite)),
521which is a block size (see [`$bloq`](@/docs/hoon/reference/stdlib/1c.md#bloq))
522with optional block count.
524`b` is a list of atoms.
535 |= [a=bite b=(list @)]
536 =/ [=bloq =step] ?^(a a [a *step])
540 %+ add $(i +(i), b t.b)
541 (lsh [bloq (mul step i)] (end [bloq step] i.b))
547 > `@ub`(rep 2 [1 2 3 4 ~]) :: @ub is the binary aura
553 > (rep 0 [0 0 0 1 ~])
556 > `@ub`(rep 0 [0 0 0 1 ~])
562 > `@ub`(rep 0 [1 0 1 0 ~])
565 > `@ub`(rep 0 [1 2 3 4 ~])
568 > (rep 0 [0 1 0 1 ~])
571 > (rep 0 [1 0 1 0 1 ~])
577 > `@ub`(rep 3 [12 166 8 34 ~])
578 0b10.0010.0000.1000.1010.0110.0000.1100
583 > `@t`(rep 3 "abcd") :: @t is the text aura
593Produces a list of atoms from the bits of `b` using block size `a`.
597`a` is an atom slice specifier (see [`$bite`](@/docs/hoon/reference/stdlib/1c.md#bite)),
598which is a block size (see [`$bloq`](@/docs/hoon/reference/stdlib/1c.md#bloq))
599with optional block count.
615 [(end a b) $(b (rsh a b))]
621 > `@ub`155 :: @ub is the binary aura
648 > `tape`(rip 3 'abcd')
658Right-shifts `b` by `step` blocks of size `bloq`, producing an atom.
662`a` is an atom slice specifier (see [`$bite`](@/docs/hoon/reference/stdlib/1c.md#bite)),
663which is a block size (see [`$bloq`](@/docs/hoon/reference/stdlib/1c.md#bloq))
664with optional block count.
678 =/ [=bloq =step] ?^(a a [a *step])
679 (div b (bex (mul (bex bloq) step)))
685 > `@ub`145 :: @ub is the binary aura
688 > `@ub`(rsh [1 1] 145)
697 > `@ub`(rsh [2 1] 145)
706 > `@ub`(rsh [0 1] 10)
715 > `@t`(rsh [3 1] 'abc')
718 > `@ux`(rsh [3 1] 'abc')
728Disassembles atom `b` into slices specified by `a`, applies `c` to each slice,
729and reassembles the results back into an atom.
733`a` is an atom slice specifier (see [`$bite`](@/docs/hoon/reference/stdlib/1c.md#bite)),
734which is a block size (see [`$bloq`](@/docs/hoon/reference/stdlib/1c.md#bloq))
735with optional block count.
739`c` is a gate that accepts an atom and produces an atom.
750 |= [a=bite b=@ c=$-(@ @)]
751 (rep a (turn (rip a b) c))
757 > `@ux`65.535 :: @ux is the hexadecimal aura
760 > `@ux`(run 2 65.535 dec) :: dec is the decrement gate
770Disassembles atom `b` into slices specified by `a`, applies `c` to each slice,
771and assembles the results back into a.
775`a` is an atom slice specifier (see [`$bite`](@/docs/hoon/reference/stdlib/1c.md#bite)),
776which is a block size (see [`$bloq`](@/docs/hoon/reference/stdlib/1c.md#bloq))
777with optional block count.
781`c` is a gate that accepts an atom.
792 |* [a=bite b=@ c=$-(@ *)]
799 > `@ux`65.535 :: @ux is the hexadecimal aura
802 > `(list @ux)`(rut 2 65.535 dec) :: dec is the decrement gate
812Switches little-endian to big-endian and vice versa: produces an atom by
813reversing the block order of `b` using block size `a`.
818`a` is a block size (see [`++bloq`](@/docs/hoon/reference/stdlib/1c.md)).
829 ++ swp |=([a=bloq b=@] (rep a (flop (rip a b))))
835 > `@ub`24 :: @ub is the binary aura
857Computes the base-2 logarithm of `a`, producing an atom.
905Core that contains arms for `bloq` and modular integer operations.
920Produces the difference between two atoms in the modular basis
938 ++ dif |=([b=@ c=@] (sit (sub (add out (sit b)) (sit c))))
944 > (~(dif fe 3) 63 64)
965 > (~(dif fe 2) 63 64)
974Inverts the order of the modular field.
978`b` is a `bloq`. (see [`++bloq`](@/docs/hoon/reference/stdlib/1c.md))
987 ++ inv |=(b=@ (sub (dec out) (sit b)))
1017Reverses bytes within a block.
1021`b` is a `bloq`. (see [`++bloq`](@/docs/hoon/reference/stdlib/1c.md))
1036 (lsh c 1 $(a c, b (cut c [0 1] b)))
1037 $(a c, b (cut c [1 1] b))
1086 72.057.594.037.927.936
1089 144.115.188.075.855.872
1092 216.172.782.113.783.808
1095 288.230.376.151.711.744
1098 360.287.970.189.639.680
1106Produces the maximum integer value that the current block can store; `2^a^a`.
1119 ++ out (bex (bex a))
1141 \/179.769.313.486.231.590.772.930.519.078.902.473.361.797.697.894.230.657.273\/
1142 .430.081.157.732.675.805.500.963.132.708.477.322.407.536.021.120.113.879.87
1143 1.393.357.658.789.768.814.416.622.492.847.430.639.474.124.377.767.893.424.8
1144 65.485.276.302.219.601.246.094.119.453.082.952.085.005.768.838.150.682.342.
1145 462.881.473.913.110.540.827.237.163.350.510.684.586.298.239.947.245.938.479
1146 .716.304.835.356.329.624.224.137.216
1155Rolls `d` to the left by `c` `b`-sized blocks.
1174 ++ rol |= [b=bloq c=@ d=@] ^- @
1176 =+ f=(bex (sub a b))
1178 (sit (con (lsh b g e) (rsh b (sub f g) e)))
1184 > `@ux`(~(rol fe 6) 4 3 0xabac.dedf.1213)
1185 0x1213.0000.abac.dedf
1187 > `@ux`(~(rol fe 6) 4 2 0xabac.dedf.1213)
1188 0xdedf.1213.0000.abac
1190 > `@t`(~(rol fe 5) 3 1 'dfgh')
1193 > `@t`(~(rol fe 5) 3 2 'dfgh')
1196 > `@t`(~(rol fe 5) 3 0 'dfgh')
1205Rolls `d` to the right by `c` `b`-sized blocks.
1224 ++ ror |= [b=bloq c=@ d=@] ^- @
1226 =+ f=(bex (sub a b))
1228 (sit (con (rsh b g e) (lsh b (sub f g) e)))
1234 > `@ux`(~(ror fe 6) 4 1 0xabac.dedf.1213)
1235 0x1213.0000.abac.dedf
1237 > `@ux`(~(ror fe 6) 3 5 0xabac.dedf.1213)
1238 0xacde.df12.1300.00ab
1240 > `@ux`(~(ror fe 6) 3 3 0xabac.dedf.1213)
1241 0xdf12.1300.00ab.acde
1243 > `@t`(~(rol fe 5) 3 0 'hijk')
1246 > `@t`(~(rol fe 5) 3 1 'hijk')
1249 > `@t`(~(rol fe 5) 3 2 'hijk')
1258Produces an atom in the current modular block representation.
1273 ++ sit |=(b=@ (end a 1 b))
1291 > (~(sit fe 2) 10.000)
1319Sums two numbers in this modular field.
1336 ++ sum |=([b=@ c=@] (sit (add b c)))
1342 > (~(sum fe 3) 10 250)
1351 > (~(sum fe 2) 14 2)
1354 > (~(sum fe 2) 14 3)
1357 > (~(sum fe 4) 10.000 256)
1360 > (~(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