Bitwise operations using binary representation of integers
Bitwise "or" for
Bitwise "and" for
λ a b, a && !b for
pos_num. For example,
ldiff 5 9 = 4:
Bitwise "xor" for
a.test_bit n is
tt iff the
n-th bit (starting from the LSB) in the binary representation
a is active. If the size of
a is less than
n, this evaluates to
Right-shift the binary representation of a
Alternative representation of integers using a sign bit at the end.
The convention on sign here is to have the argument to
the sign of the MSB itself, with all higher bits set to the negation
of this sign. The result is interpreted in two's complement.
13 = ..0001101(base 2) = nz (bit1 (bit0 (bit1 (msb tt)))) -13 = ..1110011(base 2) = nz (bit1 (bit1 (bit0 (msb ff))))
0 = ..0000000(base 2) = zero ff -1 = ..1111111(base 2) = zero tt
snum representation uses a bit string, essentially a list of 0 (
ff) and 1 (
and the negation of the MSB is sign-extended to all higher bits.