Number tools: base converter, bitwise, bytes

These tools are for the places where numbers stop being just numbers: a flag field read as bits, an address or a color written in hex, a file size that depends on whether a kilobyte is 1,000 bytes or 1,024.

The base converter reads and writes binary, octal, decimal, hex and the other bases up to 36, exactly, with no rounding past 2^53. The bitwise calculator works out AND, OR, XOR, NOT and shifts at a width you choose, with both the signed and the unsigned reading, so you can see why NOT 5 is 250 at 8 bits. The data size converter keeps SI and IEC units apart, kB and KiB, MB and MiB, and times a download at a given speed.

Two traps account for most of the confusion. The same bits mean different numbers depending on width and signedness: 0b11111111 is 255 unsigned and −1 in 8-bit two’s complement. And drives are sold in SI units while operating systems often count in powers of two, which is why a 1 TB drive shows up as about 931 GiB.

The Bit Flip game turns the bitwise operators into puzzles.

The tools

Learn it by playing

Answers