2c: Bit Arithmetic
+bex
Binary exponent.
Computes the result of 2^a, where .a is a block size (see $bloq), producing an $atom.
Accepts
.a is a +bloq.
Produces
An $atom.
Source
++ bex
~/ %bex
|= a=bloq
^- @
?: =(0 a) 1
(mul 2 $(a (dec a)))Examples
> (bex 4)
16+can
Assemble.
Produces an $atom from a +list .b of length-value pairs .p and .q, where .p is the length in blocks of size .a, and .q is an $atomic value.
Accepts
.a is a block size (see +bloq).
.b is a +list of length-value pairs, .p and .q:
.pis a+step..qis a@.
Produces
An $atom.
Source
Examples
+cat
Concatenate.
Concatenates two $atoms, .b and .c, according to block size .a, producing an $atom.
Accepts
.a is a block size (see +bloq).
.b is an $atom.
.c is an $atom.
Produces
An $atom.
Source
Examples
+clz
Leading zeros.
Counts the leading zero bits of .b within the block width given by .a.
Accepts
.a is a $bite.
.b is an $atom.
Produces
An $atom.
Source
Examples
+ctz
Trailing zeros.
Counts the trailing zero bits of .a. Produces 0 for an input of 0.
Accepts
.a is an $atom.
Produces
An $atom.
Source
Examples
+cut
Slice.
Slices .c blocks of size .a that are positioned .b blocks from the end of .d. That slice is produced as an $atom.
Accepts
.a is a block size (see +bloq).
[b c] where:
.d is an $atom.
Produces
An $atom.
Source
Examples
+end
Tail.
Produces an $atom by taking the last +step blocks of size +bloq from .b.
Accepts
.a is an $atom slice specifier (see $bite), which is a block size (see +bloq) with optional block count.
.b is an $atom.
Produces
An $atom.
Source
Examples
+fil
Fill bloqstream.
Produces an $atom by repeating .c for .b blocks of size .a.
Accepts
.a is a block size (see +bloq).
.b is a +step.
.c is an $atom.
Produces
An $atom.
Source
Examples
+ham
Population count.
Counts the set bits of .a — the Hamming weight, or popcount.
Accepts
.a is an $atom.
Produces
An $atom.
Source
Examples
+hew
Cut many.
Cuts several values out of an atom in sequence, shaped by the argument you apply the resulting gate to, and reports where it left off.
Accepts
.a is a $bite, the block size and starting offset.
.c is an $atom, the source.
The product is a wet gate; apply it to a shape describing how many blocks each field should take.
Produces
A cell of the filled-in shape and the new [bloq step] position.
Source
Examples
Cutting two blocks as one value:
Cutting two single blocks into a cell:
+lsh
Left-shift.
Produces an $atom by left-shifting .b by +step blocks of size +bloq.
Accepts
.a is an $atom slice specifier (see $bite), which is a block size (see +bloq) with optional block count.
.b is an $atom.
Produces
An $atom.
Source
Examples
+met
Measure.
Computes the number of blocks of size .a in .b, producing an $atom.
Accepts
.a is a block size (see +bloq).
.b is an $atom.
Source
Examples
+rap
Assemble non-zero.
Concatenates a +list of $atoms .b using block size .a, producing an $atom.
Accepts
.a is a block size (see +bloq).
.b is a +list of $atoms.
Produces
An $atom.
Source
Examples
Discussion
Any element of the value 0 is not included in concatenation.
+rep
Assemble single.
Produces an $atom by assembling a +list of $atoms .b using block size .a.
Accepts
.a is an $atom slice specifier (see $bite), which is a block size (see +bloq) with optional block count.
.b is a +list of $atoms.
Produces
An $atom.
Source
Examples
+rev
Reverses block order, accounting for leading zeroes.
Produces an $atom from the bits of .dat in reverse order according to a block size .boz and a size .len.
If the total size is less than the length of .dat, then only the first bits of .dat up to the total size will be taken and reversed. If the total size is longer, trailing zeroes will be added.
Accepts
.boz is a block size with optional block count (see +bloq).
.len is a @ud of the number of blocks of size .boz to be reversed.
.dat is an $atom.
Produces
An $atom.
Source
Examples
+rig
Convert block sizes.
Re-expresses the step of $bite .bite in terms of block size .b.
Accepts
.bite is a $bite.
.b is a $bloq.
Produces
A +step.
Source
Examples
+rip
Disassemble.
Produces a +list of $atoms from the bits of .b using block size .a.
Accepts
.a is an $atom slice specifier (see $bite), which is a block size (see +bloq) with optional block count.
.b is an $atom.
Produces
A +list of $atoms.
Source
Examples
+rsh
Right-shift.
Right-shifts .b by +step blocks of size +bloq, producing an $atom.
Accepts
.a is an $atom slice specifier (see $bite), which is a block size (see +bloq) with optional block count.
.b is an $atom.
Produces
An $atom.
Source
Examples
+run
+turn into $atom.
Disassembles $atom .b into slices specified by .a, applies .c to each slice, and reassembles the results back into an $atom.
Accepts
.a is an $atom slice specifier (see $bite), which is a block size (see +bloq) with optional block count.
.b is an $atom.
.c is a gate that accepts an $atom and produces an $atom.
Produces
An $atom.
Source
Examples
+rut
+turn into +list.
Disassembles $atom .b into slices specified by .a, applies .c to each slice, and assembles the results back into a.
Accepts
.a is an $atom slice specifier (see $bite), which is a block size (see +bloq) with optional block count.
.b is an $atom.
.c is a gate that accepts an $atom.
Produces
A +list.
Source
Examples
+sew
Stitch one $atom into another.
Replace .c blocks of size .a at offset .b of $atom .e with .c blocks of size .a from $atom .d.
That is, take (end [a c] d) from .d and overwrite the (cut a [b c] e) part of .e.
Or in simpler terms, take from the start of .d and replace some part of .e with it.
Accepts
.a is a $bloq (block size).
[b c d] where:
.bis a step specifying the number of+bloqs to offset..bis a step specifying the number of+bloqs to replace..dis the donor$atom.
.e is the recipient $atom.
Produces
An $atom.
Source
Examples
+swp
Reverse block order.
Switches little-endian to big-endian and vice versa: produces an $atom by reversing the block order of .b using block size .a.
Accepts
.a is a block size (see +bloq).
.b is an $atom.
Produces
An $atom.
Source
Examples
+xeb
Binary logarithm.
Computes the base-2 logarithm of .a, producing an $atom.
Accepts
.a is an $atom.
Produces
An $atom.
Source
Examples
+fe
Modulo bloq.
Core that contains arms for +bloq and modular integer operations.
Accepts
.a is a +bloq.
Source
+dif:fe
Produces the difference between two $atoms in the modular basis representation.
Accepts
.a is a +bloq (and is the sample of the parent core).
.b is an $atom.
.c is an $atom.
Produces
A @s.
Source
Examples
+inv:fe
Inverse.
Inverts the order of the modular field.
Accepts
.a is a +bloq (and is the sample of the parent core).
.b is a +bloq. (see +bloq)
Produces
An $atom.
Source
Examples
+net:fe
Flip endianness.
Reverses bytes within a block.
Accepts
.a is a +bloq (and the sample of the parent core).
.b is a +bloq (see +bloq).
Produces
An $atom.
Source
Examples
+out:fe
Max integer value.
Produces the maximum integer value that the current block can store; 2^a^a.
Accepts
.a is a +bloq (and is the sample of the parent core).
Produces
An $atom.
Source
Examples
+rol:fe
Roll left.
Rolls .d to the left by .c .b-sized blocks.
Accepts
.a is a +bloq (and is the sample of the parent core).
.b is a +bloq.
.c is an $atom.
.d is an $atom.
Produces
An $atom.
Source
Examples
+ror:fe
Roll right.
Rolls .d to the right by .c .b-sized blocks.
Accepts
.a is a +bloq (and is the sample of the parent core).
.b is a +bloq.
.c is an $atom.
.d is an $atom.
Produces
An $atom.
Source
Examples
+sum:fe
Sum.
Sums two numbers in this modular field.
Accepts
.a is a +bloq (and is the sample of the parent core).
.b is an $atom.
.c is an $atom.
Produces
An $atom.
Source
Examples
+sit:fe
Enforce modulo.
Produces an $atom in the current modular block representation.
Accepts
.a is a +bloq (and is the sample of the parent core).
.b is an $atom.
Produces
An $atom.
Source
Examples
Last updated