The Crow Programming Language

bits

An int's bits — read as two's complement of any width — and a character's code.

Import with use bits. An int's bits and a character's code, for the algorithms that work on them — a set of small numbers held as one int's bits, a hash, a parser that reads character codes. An int is a whole number of any size, read as two's complement with as many bits as it needs (as Python reads one): bitand[n, -1] is n, a negative number's high bits are ones, and a shift right rounds down. Every function works identically in both modes (crow_runtime::bits). An int stays in 64 bits where the width rules show it fits (Numbers That Keep Every Digit); a shift left by a count nothing bounds grows, so a mask meant to stay a width is cut to it with bitand after the shift.

FunctionDescriptionExample
bitand[a, b]The bits both haveBits and character codes: use bits
bitor[a, b]The bits either hasBits and character codes: use bits
bitxor[a, b]The bits one has and the other has not; bitxor[a, -1] flips every bit (-a - 1)Bits and character codes: use bits
bitcount[a]How many ones the bits of abs[a] holdBits and character codes: use bits
shift[a, n]a times 2^n; for a negative n, a divided by 2^-n and rounded down (shift[-7, -1] is -4). A number past 2^32 bits stopsBits and character codes: use bits
code[ch]The code of a one-character text, its Unicode scalar value (code['A'] is 65); any other length stops: code takes one character, got "ab" (2 characters)Bits and character codes: use bits · JSON · Views: the whole element vocabulary · Web: responses and submodules
char[n]The character whose code is n (char[233] is 'é'); a number that is no character's code stopsBits and character codes: use bits
use bits

fn queens[n, mask, row, cols, d1, d2]
    if row eq n
        return 1
    count = 0
    free = bitand[bitxor[bitor[bitor[cols, d1], d2], -1], mask]
    while free ne 0
        bit = bitand[free, -free]                --- the lowest free column
        free = bitxor[free, bit]
        count = count + queens[n, mask, row + 1, bitor[cols, bit], bitand[shift[bitor[d1, bit], 1], mask], shift[bitor[d2, bit], -1]]
    return count

log[queens[8, shift[1, 8] - 1, 0, 0, 0, 0]]     --- 92

Design Note: bits by name, in a module. Considered: the operators most languages write — &, |, ^, <<, >> — or the functions in the core. Decided (Vijay, 2026-10-11): named functions in a module a program imports. ^ is already the power, and symbols are shift-key syntax whose cost needs a reason a few algorithms do not give; the core is frozen by the budget rule, and code is a variable's name in many programs, so the names are taken only where a program asks for them. Before the module, a program had no way to read a character's code at all (sys has one, and a program may not import sys).

Generated by crow test --docs --write from the language specification, section 11 and 13. Edit the spec, not this page.