Code
Ways of writing that hide nothing by design — bases, bits, binary formats, floats, Unicode, Morse, QR codes, Roman numerals, timestamps, coordinates, check digits — read and written both ways.
Bit Operations
Works an operation on the bits of a number in a word of 8, 16, 32 or 64 bits: AND, OR, XOR and NOT, addition and subtraction with the carry into each place, shifts with or without the sign, rotations, the bits reversed and the bytes’ order swapped. Each is drawn bit by bit, every bit of the result naming where it came from.
History, how it works, how it was checked, limits
History
A computer keeps a number as a word of bits and works on it place by place. AND, OR, XOR and NOT are the operations of logic taken a bit at a time; a shift moves every bit along and so multiplies or divides by two; a rotation moves them round; and addition carries from each place to the next as it does on paper. They are the small steps that ciphers, checksums and hashes are made of, which is why they stand here.
How it works
A number is typed in decimal, as 0x… in hexadecimal or as 0b… in binary; a negative number is kept as its two’s complement. The word is 8, 16, 32 or 64 bits. The result is given in hexadecimal and binary, as an unsigned and a signed number, with its count of 1s. The figure draws A, B and the result bit under bit, the highest at the left: for addition and subtraction the carry or borrow into each place, and a carry out of the word said to be lost; for a shift the zeros or the copies of the sign bit that came in, marked; for a rotation, a reversal and a swap of the bytes each bit of the result names the place in A it came from.
How it was checked
The operations are definitions; ECMA-262 states them for 32-bit words, and the tests set every operation beside those operators of JavaScript’s and beside whole-number arithmetic in BigInt on 8, 16 and 64 bits, some 20,000 seeded cases: addition and subtraction modulo the word, a shift as a multiplication or a floored division by a power of two, two rotations and two reversals undoing each other. The carries drawn are checked to be those of the addition they stand under.
The tests hold 14 checks of this tool; 1 rests on outside material:
- Another’s computation 5,000 seeded pairs of 32-bit words: each of AND, OR, XOR, NOT, add, subtract, the three shifts and both rotations equals Node’s own operator (&, |, ^, ~, +, −, <<, >>>, >>)
Limits
One operation at a time, on whole words of four widths. No multiplication or division, no arbitrary width, no floating point. A shift by more places than the word has gives 0, or the sign in every place, where some processors would take the count modulo the width.