TOOLTIKI Lovable tool, really free

Why programmers count in sixteens

Hexadecimal exists because one hex digit maps exactly onto four bits. Sixteen is two to the fourth, so every group of four binary digits has exactly one hex digit and no remainder — FF is 11111111, and the conversion needs no arithmetic at all. Decimal has no such relationship with binary, which is why nobody reads memory addresses in base ten.

Octal survives for the same reason with three bits per digit, which is why Unix file permissions are written 755 rather than 493.

How do the bases line up?

Only bases that are powers of two convert to binary digit by digit. Everything else has to go through decimal.

Base Digits Bits per digit Where it survives
2 0–1 1 Everything underneath
8 0–7 3 Unix permissions
10 0–9 Humans
16 0–9, A–F 4 Addresses, colours, hashes
36 0–9, A–Z Short identifiers

Base 36 is the largest case-insensitive alphanumeric base, which is why short URL identifiers and licence keys use it — it packs the most value into the fewest characters that survive being read aloud or typed in.

How do you convert by hand?

Two methods, one for each direction, and both work for any base.

Going to decimal: multiply each digit by the base raised to its position from the right, and add. 2AF is 2×256 + 10×16 + 15 = 687.

Coming from decimal: divide repeatedly by the target base and read the remainders backwards. 255 ÷ 16 gives 15 remainder 15, which is F and F — so FF.

Worth doing once so the structure is obvious, and worth using a tool for thereafter. The repeated-division method is the general one and it is why an arbitrary base conversion goes through decimal internally.

Why is grouping so important in binary?

Because a long binary string is nearly unreadable without it. 11111111 is legible; 1111111111111111 is a counting exercise.

The convention is groups of four or eight, and it is not arbitrary — four is one hex digit and eight is one byte. Reading 1100 1010 as CA is instant once the grouping is there and impossible when it is not.

The same applies to IP addresses. 10.20.30.40 in binary is 00001010 00010100 00011110 00101000, and the octet grouping is what makes a subnet prefix readable as a count of leading bits.

Where does hex turn up outside code?

Colours, most visibly. A hex colour is three bytes — red, green and blue — so #1F6E60 is 31, 110, 96, and the colour scale article works through what to do with them.

MAC addresses, hashes, UUIDs and file signatures are all hex for the same reason: they are byte sequences with no numeric meaning, and hex is the shortest notation that maps cleanly onto bytes. Reading a SHA-256 as a decimal number would be technically possible and completely useless.

How are negative numbers stored?

In two’s complement: flip every bit and add one. In eight bits, −42 is 11010110, which read as unsigned is 214.

The scheme is chosen because it makes addition work without special cases — the same adder handles signed and unsigned values, and subtraction is just addition of the complement. That is worth a small asymmetry, and the asymmetry is real: eight bits hold −128 to 127, one more negative than positive, because zero occupies a slot on the positive side.

That off-by-one is behind a specific class of bug. Negating the most negative value overflows back to itself, so −(−128) is −128 in eight bits, and the same holds at every width.

What do the operators actually do?

Compare bit by bit, which is obvious once the columns line up. 12 AND 10 is 8 because only the eight-bit is set in both; OR gives 14 and XOR gives 6.

Shifting is multiplication and division by powers of two: shifting left by three multiplies by eight, so 5 becomes 40. Bits pushed past the end are discarded, which is why a left shift is only equivalent to multiplying while the result still fits.

The two right shifts differ only for negative numbers, and the difference matters. An arithmetic shift preserves the sign bit; a logical shift fills with zeros, so a negative number becomes a very large positive one. Choosing the wrong one is a bug that only appears with negative input.

Questions people ask

Why is FF 255? Because two hex digits are eight bits, and eight bits hold 0 to 255. That is also why colour channels run 00 to FF.

Why does octal survive at all? Unix permissions, where three-bit grouping genuinely is the clearest notation — read, write and execute is exactly three bits per class.

Is base 36 case-sensitive? No, which is the point. Base 62 adds lower case and doubles the density, at the cost of identifiers that cannot be dictated over a phone.

Why 32-bit operations? Because that is what most language runtimes use for bitwise operators regardless of the underlying integer size. Shifts beyond 31 places wrap rather than clearing the value.

Four bits to a hex digit is the fact everything else hangs off. Hex to decimal and decimal to hex handle the common pair, binary to decimal and octal to decimal the others, the number base converter covers arbitrary bases up to 36, decimal to binary, decimal to octal, hex to binary and binary to hex take the power-of-two shortcuts directly, and the two’s complement, bitwise and bit shift calculators show what the bits are doing while you do it.