2title = "2c: Bit Arithmetic"
11Computes the result of `2^a`, where `a` is a block size (see [$bloq](/docs/hoon/reference/stdlib/1c#bloq)), producing an atom.
55Produces an atom from a list `b` of length-value pairs `p` and `q`,
56where `p` is the length in blocks of size `a`, and `q` is an atomic
61`a` is a block size (see [`$bloq`](/docs/hoon/reference/stdlib/1c#bloq)).
63`b` is a `list` of length-value pairs, `p` and `q`:
65- `p` is a [step](/docs/hoon/reference/stdlib/1c/#step).
77 |= [a=bloq b=(list [p=step q=@])]
80 (add (end [a p.i.b] q.i.b) (lsh [a p.i.b] $(b t.b)))
86> `@ub`21 :: @ub is the binary aura
91> `@ub`(can 3 ~[[1 21]])
96> `@ub`(can 3 ~[[1 1]])
101> `@ub`(can 0 ~[[1 255]])
106> `@ux`(can 3 [3 0xc1] [1 0xa] ~) :: @ux is the hexadecimal aura
111> `@ux`(can 3 [3 0xc1] [1 0xa] [1 0x23] ~)
116> `@ux`(can 4 [3 0xc1] [1 0xa] [1 0x23] ~)
1170x23.000a.0000.0000.00c1
121> `@ux`(can 3 ~[[1 'a'] [2 'bc']])
131Concatenates two atoms, `b` and `c`, according to block size `a`, producing an
136`a` is a block size (see [`$bloq`](/docs/hoon/reference/stdlib/1c#bloq)).
152 (add (lsh [a (met a b)] c) b)
158> `@ub`(cat 3 1 0) :: @ub is the binary aura
173> `@ub`(cat 3 256 255)
1740b1111.1111.0000.0001.0000.0000
175> `@ub`(cat 2 256 255)
1760b1111.1111.0001.0000.0000
189Slices `c` blocks of size `a` that are positioned `b` blocks from the end of
190`d`. That slice is produced as an atom.
194`a` is a block size (see [`$bloq`](/docs/hoon/reference/stdlib/1c)).
198- `b` is a [step](/docs/hoon/reference/stdlib/1c#step).
199- `c` is a [step](/docs/hoon/reference/stdlib/1c#step).
212 |= [a=bloq [b=step c=step] d=@]
213 (end [a c] (rsh [a b] d))
226> `@t`(cut 3 [0 3] 'abcdefgh') :: @t is the cord aura
228> `@t`(cut 3 [1 3] 'abcdefgh')
233> `@ub`(cut 0 [0 3] 0b1111.0000.1101) :: @ub is the binary aura
235> `@ub`(cut 0 [0 6] 0b1111.0000.1101)
237> `@ub`(cut 0 [4 6] 0b1111.0000.1101)
239> `@ub`(cut 0 [3 6] 0b1111.0000.1101)
249Produces an atom by taking the last `step` blocks of size `bloq` from `b`.
253`a` is an atom slice specifier (see [`$bite`](/docs/hoon/reference/stdlib/1c#bite)),
254which is a block size (see [`$bloq`](/docs/hoon/reference/stdlib/1c#bloq))
255with optional block count.
269 =/ [=bloq =step] ?^(a a [a *step])
270 (mod b (bex (mul (bex bloq) step)))
287> `@ub`12 :: @ub is the binary aura
300> `@ux`'abc' :: @ux is the hexademical aura
302> `@ux`(end [3 2] 'abc')
304> `@t`(end [3 2] 'abc') :: @t is the cord aura
314Produces an atom by repeating `c` for `b` blocks of size `a`.
318`a` is a block size (see [`$bloq`](/docs/hoon/reference/stdlib/1c#bloq)).
320`b` is a [step](/docs/hoon/reference/stdlib/1c#step).
333 |= [a=bloq b=step c=@]
340 $(d (add c (lsh a d)), n +(n))
346> `@t`(fil 3 5 %a) :: @t is the cord (string) aura
351> `@t`(fil 5 10 %ceeb)
352'ceebceebceebceebceebceebceebceebceebceeb'
356> `@t`(fil 4 10 'eced')
357'ecececececececececec'
361> `@tas`(fil 4 10 %bf) :: @tas is the term aura
366> `@ub`(fil 2 6 1) :: @ub is the binary aura
3670b1.0001.0001.0001.0001.0001
376Produces an atom by left-shifting `b` by `step` blocks of size `bloq`.
380`a` is an atom slice specifier (see [`$bite`](/docs/hoon/reference/stdlib/1c#bite)),
381which is a block size (see [`$bloq`](/docs/hoon/reference/stdlib/1c#bloq))
382with optional block count.
396 =/ [=bloq =step] ?^(a a [a *step])
397 (mul b (bex (mul (bex bloq) step)))
403> `@ub`1 :: @ub is the binary aura
416> `@ub`(lsh [3 1] 255)
428Computes the number of blocks of size `a` in `b`, producing an atom.
432`a` is a block size (see [`$bloq`](/docs/hoon/reference/stdlib/1c/bloq)).
446 $(b (rsh a b), c +(c))
476Concatenates a list of atoms `b` using block size `a`, producing an atom.
480`a` is a block size (see [`++bloq`](/docs/hoon/reference/stdlib/1c)).
482`b` is a `list` of atoms.
493 |= [a=bloq b=(list @)]
502> `@ub`(rap 2 [1 2 3 4 ~]) :: @ub is the binary aura
504> `@ub`(rap 1 [1 2 3 4 ~])
518> (rap 0 [0 1 0 0 1 2 ~])
528Any element of the value `0` is not included in concatenation.
536Produces an atom by assembling a list of atoms `b` using block size `a`.
540`a` is an atom slice specifier (see [`$bite`](/docs/hoon/reference/stdlib/1c#bite)),
541which is a block size (see [`$bloq`](/docs/hoon/reference/stdlib/1c#bloq))
542with optional block count.
544`b` is a list of atoms.
555 |= [a=bite b=(list @)]
556 =/ [=bloq =step] ?^(a a [a *step])
560 %+ add $(i +(i), b t.b)
561 (lsh [bloq (mul step i)] (end [bloq step] i.b))
567> `@ub`(rep 2 [1 2 3 4 ~]) :: @ub is the binary aura
579> `@ub`(rep 0 [0 0 0 1 ~])
586> `@ub`(rep 0 [1 0 1 0 ~])
588> `@ub`(rep 0 [1 2 3 4 ~])
595> (rep 0 [1 0 1 0 1 ~])
602> `@ub`(rep 3 [12 166 8 34 ~])
6030b10.0010.0000.1000.1010.0110.0000.1100
609> `@t`(rep 3 "abcd") :: @t is the text aura
617Reverses block order, accounting for leading zeroes.
619Produces an atom from the bits of `dat` in reverse order according to a block
620size `boz` and a size `len`.
622If the total size is less than the length of `dat`, then only the first
623bits of `dat` up to the total size will be taken and reversed. If the total size
624is longer, trailing zeroes will be added.
628`boz` is a block size with optional block count (see
629[`$bloq`](/docs/hoon/reference/stdlib/1c#bloq)).
631`len` is a `@ud` of the number of blocks of size `boz` to be reversed.
644 |= [boz=bloq len=@ud dat=@]
646 =. dat (end [boz len] dat)
648 [boz (sub len (met boz dat))]
655> =a 0b1111.0000.1111.1010.0011
6570b1100.0101.1111.0000.1111
6610b11.1010.1111.0000.1111
6650b11.1010.1111.0000.1111.0000
683Produces a list of atoms from the bits of `b` using block size `a`.
687`a` is an atom slice specifier (see [`$bite`](/docs/hoon/reference/stdlib/1c#bite)),
688which is a block size (see [`$bloq`](/docs/hoon/reference/stdlib/1c#bloq))
689with optional block count.
705 [(end a b) $(b (rsh a b))]
711> `@ub`155 :: @ub is the binary aura
738> `tape`(rip 3 'abcd')
748Right-shifts `b` by `step` blocks of size `bloq`, producing an atom.
752`a` is an atom slice specifier (see [`$bite`](/docs/hoon/reference/stdlib/1c#bite)),
753which is a block size (see [`$bloq`](/docs/hoon/reference/stdlib/1c#bloq))
754with optional block count.
768 =/ [=bloq =step] ?^(a a [a *step])
769 (div b (bex (mul (bex bloq) step)))
775> `@ub`145 :: @ub is the binary aura
777> `@ub`(rsh [1 1] 145)
783> `@ub`(rsh [2 1] 145)
801> `@t`(rsh [3 1] 'abc')
803> `@ux`(rsh [3 1] 'abc')
813Disassembles atom `b` into slices specified by `a`, applies `c` to each slice,
814and reassembles the results back into an atom.
818`a` is an atom slice specifier (see [`$bite`](/docs/hoon/reference/stdlib/1c#bite)),
819which is a block size (see [`$bloq`](/docs/hoon/reference/stdlib/1c#bloq))
820with optional block count.
824`c` is a gate that accepts an atom and produces an atom.
835 |= [a=bite b=@ c=$-(@ @)]
836 (rep a (turn (rip a b) c))
842 > `@ux`65.535 :: @ux is the hexadecimal aura
844 > `@ux`(run 2 65.535 dec) :: dec is the decrement gate
854Disassembles atom `b` into slices specified by `a`, applies `c` to each slice,
855and assembles the results back into a.
859`a` is an atom slice specifier (see [`$bite`](/docs/hoon/reference/stdlib/1c#bite)),
860which is a block size (see [`$bloq`](/docs/hoon/reference/stdlib/1c#bloq))
861with optional block count.
865`c` is a gate that accepts an atom.
876 |* [a=bite b=@ c=$-(@ *)]
883> `@ux`65.535 :: @ux is the hexadecimal aura
885> `(list @ux)`(rut 2 65.535 dec) :: dec is the decrement gate
893Stitch one atom into another
895Replace `c` blocks of size `a` at offset `b` of atom `e` with `c` blocks of size `a` from atom `d`.
897That is, take `(end [a c] d)` from `d` and overwrite the `(cut a [b c] e)` part of `e`.
899Or in simpler terms, take from the start of `d` and replace some part of `e` with it.
903`a` is a [$bloq](/docs/hoon/reference/stdlib/1c#bite) (block size).
907- `b` is a [step](/docs/hoon/reference/stdlib/1c#step) specifying the number of `bloq`s to offset.
908- `b` is a [step](/docs/hoon/reference/stdlib/1c#step) specifying the number of `bloq`s to replace.
909- `d` is the donor atom.
911`e` is the recipient atom.
922 |= [a=bloq [b=step c=step d=@] e=@]
933> `@t`(sew 3 [0 0 'XXXX'] 'OOOO')
935> `@t`(sew 3 [0 1 'XXXX'] 'OOOO')
937> `@t`(sew 3 [2 1 'XXXX'] 'OOOO')
939> `@t`(sew 3 [2 2 'XXXX'] 'OOOO')
941> `@t`(sew 3 [0 4 'XXXX'] 'OOOO')
951Switches little-endian to big-endian and vice versa: produces an atom by
952reversing the block order of `b` using block size `a`.
956`a` is a block size (see [`$bloq`](/docs/hoon/reference/stdlib/1c#bloq)).
970 (rep a (flop (rip a b)))
976> `@ub`24 :: @ub is the binary aura
997Computes the base-2 logarithm of `a`, producing an atom.
1055Core that contains arms for `bloq` and modular integer operations.
1071Produces the difference between two atoms in the modular basis
1076`a` is a `bloq` (and is the sample of the parent core).
1090 |=([b=@ c=@] (sit (sub (add out (sit b)) (sit c))))
1096> (~(dif fe 3) 63 64)
1116> (~(dif fe 2) 63 64)
1126Inverts the order of the modular field.
1130`a` is a `bloq` (and is the sample of the parent core).
1132`b` is a `bloq`. (see [`$bloq`](/docs/hoon/reference/stdlib/1c#bloq))
1141++ inv |=(b=@ (sub (dec out) (sit b)))
1173Reverses bytes within a block.
1177`a` is a `bloq` (and the sample of the parent core).
1179`b` is a `bloq`. (see [`$bloq`](/docs/hoon/reference/stdlib/1c#bloq))
1194 (lsh c $(a c, b (cut c [0 1] b)))
1195 $(a c, b (cut c [1 1] b))
123972.057.594.037.927.936
1241144.115.188.075.855.872
1243216.172.782.113.783.808
1245288.230.376.151.711.744
1247360.287.970.189.639.680
1256Produces the maximum integer value that the current block can store; `2^a^a`.
1260`a` is a `bloq` (and is the sample of the parent core).
1289\/179.769.313.486.231.590.772.930.519.078.902.473.361.797.697.894.230.657.273\/
1290 .430.081.157.732.675.805.500.963.132.708.477.322.407.536.021.120.113.879.87
1291 1.393.357.658.789.768.814.416.622.492.847.430.639.474.124.377.767.893.424.8
1292 65.485.276.302.219.601.246.094.119.453.082.952.085.005.768.838.150.682.342.
1293 462.881.473.913.110.540.827.237.163.350.510.684.586.298.239.947.245.938.479
1294 .716.304.835.356.329.624.224.137.216
1304Rolls `d` to the left by `c` `b`-sized blocks.
1308`a` is a `bloq` (and is the sample of the parent core).
1323++ rol |= [b=bloq c=@ d=@] ^- @
1325 =+ f=(bex (sub a b))
1327 (sit (con (lsh [b g] e) (rsh [b (sub f g)] e)))
1333> `@ux`(~(rol fe 6) 4 3 0xabac.dedf.1213)
13340x1213.0000.abac.dedf
1336> `@ux`(~(rol fe 6) 4 2 0xabac.dedf.1213)
13370xdedf.1213.0000.abac
1341> `@t`(~(rol fe 5) 3 1 'dfgh')
1344> `@t`(~(rol fe 5) 3 2 'dfgh')
1347> `@t`(~(rol fe 5) 3 0 'dfgh')
1357Rolls `d` to the right by `c` `b`-sized blocks.
1361`a` is a `bloq` (and is the sample of the parent core).
1376++ ror |= [b=bloq c=@ d=@] ^- @
1378 =+ f=(bex (sub a b))
1380 (sit (con (rsh [b g] e) (lsh [b (sub f g)] e)))
1386> `@ux`(~(ror fe 6) 4 1 0xabac.dedf.1213)
13870x1213.0000.abac.dedf
1389> `@ux`(~(ror fe 6) 3 5 0xabac.dedf.1213)
13900xacde.df12.1300.00ab
1392> `@ux`(~(ror fe 6) 3 3 0xabac.dedf.1213)
13930xdf12.1300.00ab.acde
1397> `@t`(~(rol fe 5) 3 0 'hijk')
1400> `@t`(~(rol fe 5) 3 1 'hijk')
1403> `@t`(~(rol fe 5) 3 2 'hijk')
1413Sums two numbers in this modular field.
1417`a` is a `bloq` (and is the sample of the parent core).
1430++ sum |=([b=@ c=@] (sit (add b c)))
1436> (~(sum fe 3) 10 250)
1455> (~(sum fe 4) 10.000 256)
1457> (~(sum fe 4) 10.000 100.000)
1467Produces an atom in the current modular block representation.
1471`a` is a `bloq` (and is the sample of the parent core).
1482++ sit |=(b=@ (end a b))
1499> (~(sit fe 2) 10.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