2title = "2c: Bit Arithmetic"
5aliases = ["/docs/reference/library/2c"]
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/library/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/library/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/library/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 `b` blocks of size `a` from `c`.
235`a` is a block size (see [`++bloq`](@/docs/hoon/library/1c.md)).
252 (mod c (bex (mul (bex a) b)))
267 > `@ub`12 :: @ub is the binary aura
282 > `@ux`'abc' :: @ux is the hexademical aura
285 > `@ux`(end 3 2 'abc')
288 > `@t`(end 3 2 'abc') :: @t is the cord aura
298Produces an atom by repeating `c` for `b` blocks of size `a`.
302`a` is a block size (see [`++bloq`](@/docs/hoon/library/1c.md)).
322 $(d (add c (lsh a 1 d)), n +(n))
328 > `@t`(fil 3 5 %a) :: @t is the cord (string) aura
331 > `@t`(fil 5 10 %ceeb)
332 'ceebceebceebceebceebceebceebceebceebceeb'
334 > `@t`(fil 4 10 %eced)
337 > `@tas`(fil 4 10 %bf) :: @tas is the term aura
338 %bfbfbfbfbfbfbfbfbfbf
340 > `@ub`(fil 2 6 1) :: @ub is the binary aura
341 0b1.0001.0001.0001.0001.0001
350Produces an atom by left-shifting `c` by `b` blocks of size `a`.
354`a` is a block size (see [`++bloq`](@/docs/hoon/library/1c.md)).
370 (mul (bex (mul (bex a) b)) c)
376 > `@ub`1 :: @ub is the binary aura
389 0b1111.1111.0000.0000
401Computes the number of blocks of size `a` in `b`, producing an atom.
405`a` is a block size (see [`++bloq`](@/docs/hoon/library/1c.md)).
419 $(b (rsh a 1 b), c +(c))
447Concatenates a list of atoms `b` using block size `a`, producing an atom.
451`a` is a block size (see [`++bloq`](@/docs/hoon/library/1c.md)).
453`b` is a `list` of atoms.
464 |= [a=bloq b=(list @)]
474 > `@ub`(rap 2 [1 2 3 4 ~]) :: @ub is the binary aura
477 > `@ub`(rap 1 [1 2 3 4 ~])
489 > (rap 0 [0 1 0 0 1 2 ~])
501Any element of the value `0` is not included in concatenation.
508Produces an atom by assembling a list of atoms `b` using block size `a`.
512`a` is a block size (see [`++bloq`](@/docs/hoon/library/1c.md)).
514`b` is a list of atoms.
525 |= [a=bloq b=(list @)]
530 (add (lsh a c (end a 1 i.b)) $(c +(c), b t.b))
536 > `@ub`(rep 2 [1 2 3 4 ~]) :: @ub is the binary aura
542 > (rep 0 [0 0 0 1 ~])
545 > `@ub`(rep 0 [0 0 0 1 ~])
551 > (rep 0 [0 1 0 0 ~])
554 > (rep 0 [0 1 0 1 ~])
557 > (rep 0 [1 0 1 0 1 ~])
563 > `@ub`(rep 3 [12 166 8 34 ~])
564 0b10.0010.0000.1000.1010.0110.0000.1100
573Produces a list of atoms from the bits of `b` using block size `a`.
577`a` is a block size (see [`++bloq`](@/docs/hoon/library/1c.md)).
593 [(end a 1 b) $(b (rsh a 1 b))]
599 > `@ub`155 :: @ub is the binary aura
633Right-shifts `c` by `b` blocks of size `a`, producing an atom.
637`a` is a block size (see [`++bloq`](@/docs/hoon/library/1c.md)).
653 (div c (bex (mul (bex a) b)))
659 > `@ub`145 :: @ub is the binary aura
686 > `@t`(rsh 3 1 'abc')
689 > `@ux`(rsh 3 1 'abc')
699Switches little-endian to big-endian and vice versa: produces an atom by
700reversing the block order of `b` using block size `a`.
705`a` is a block size (see [`++bloq`](@/docs/hoon/library/1c.md)).
716 ++ swp |=([a=bloq b=@] (rep a (flop (rip a b))))
722 > `@ub`24 :: @ub is the binary aura
744Computes the base-2 logarithm of `a`, producing an atom.
792Core that contains arms for `bloq` and modular integer operations.
807Produces the difference between two atoms in the modular basis
825 ++ dif |=([b=@ c=@] (sit (sub (add out (sit b)) (sit c))))
831 > (~(dif fe 3) 63 64)
852 > (~(dif fe 2) 63 64)
861Inverts the order of the modular field.
865`b` is a `bloq`. (see [`++bloq`](@/docs/hoon/library/1c.md))
874 ++ inv |=(b=@ (sub (dec out) (sit b)))
904Reverses bytes within a block.
908`b` is a `bloq`. (see [`++bloq`](@/docs/hoon/library/1c.md))
923 (lsh c 1 $(a c, b (cut c [0 1] b)))
924 $(a c, b (cut c [1 1] b))
973 72.057.594.037.927.936
976 144.115.188.075.855.872
979 216.172.782.113.783.808
982 288.230.376.151.711.744
985 360.287.970.189.639.680
993Produces the maximum integer value that the current block can store; `2^a^a`.
1006 ++ out (bex (bex a))
1028 \/179.769.313.486.231.590.772.930.519.078.902.473.361.797.697.894.230.657.273\/
1029 .430.081.157.732.675.805.500.963.132.708.477.322.407.536.021.120.113.879.87
1030 1.393.357.658.789.768.814.416.622.492.847.430.639.474.124.377.767.893.424.8
1031 65.485.276.302.219.601.246.094.119.453.082.952.085.005.768.838.150.682.342.
1032 462.881.473.913.110.540.827.237.163.350.510.684.586.298.239.947.245.938.479
1033 .716.304.835.356.329.624.224.137.216
1042Rolls `d` to the left by `c` `b`-sized blocks.
1061 ++ rol |= [b=bloq c=@ d=@] ^- @
1063 =+ f=(bex (sub a b))
1065 (sit (con (lsh b g e) (rsh b (sub f g) e)))
1071 > `@ux`(~(rol fe 6) 4 3 0xabac.dedf.1213)
1072 0x1213.0000.abac.dedf
1074 > `@ux`(~(rol fe 6) 4 2 0xabac.dedf.1213)
1075 0xdedf.1213.0000.abac
1077 > `@t`(~(rol fe 5) 3 1 'dfgh')
1080 > `@t`(~(rol fe 5) 3 2 'dfgh')
1083 > `@t`(~(rol fe 5) 3 0 'dfgh')
1092Rolls `d` to the right by `c` `b`-sized blocks.
1111 ++ ror |= [b=bloq c=@ d=@] ^- @
1113 =+ f=(bex (sub a b))
1115 (sit (con (rsh b g e) (lsh b (sub f g) e)))
1121 > `@ux`(~(ror fe 6) 4 1 0xabac.dedf.1213)
1122 0x1213.0000.abac.dedf
1124 > `@ux`(~(ror fe 6) 3 5 0xabac.dedf.1213)
1125 0xacde.df12.1300.00ab
1127 > `@ux`(~(ror fe 6) 3 3 0xabac.dedf.1213)
1128 0xdf12.1300.00ab.acde
1130 > `@t`(~(rol fe 5) 3 0 'hijk')
1133 > `@t`(~(rol fe 5) 3 1 'hijk')
1136 > `@t`(~(rol fe 5) 3 2 'hijk')
1145Produces an atom in the current modular block representation.
1160 ++ sit |=(b=@ (end a 1 b))
1178 > (~(sit fe 2) 10.000)
1206Sums two numbers in this modular field.
1223 ++ sum |=([b=@ c=@] (sit (add b c)))
1229 > (~(sum fe 3) 10 250)
1238 > (~(sum fe 2) 14 2)
1241 > (~(sum fe 2) 14 3)
1244 > (~(sum fe 4) 10.000 256)
1247 > (~(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