Number Systems guides

1 article · Browse the Number Systems tools →

A number system is a way of writing quantities using a fixed set of digits. People count in base 10, but computers work in base 2 because a circuit has two stable states, and programmers read that binary through base 16 (hexadecimal) and sometimes base 8 (octal). The reference below lists 0 to 255 in all four so you can look a value up directly.

The link between them is simple. Each hexadecimal digit stands for exactly four bits, so one byte is two hex digits. The value 202 is 12 × 16 + 10, which is hex CA, and CA converts digit by digit to 1100 1010 in binary. Octal groups bits in threes: 255 is 11 111 111 in binary, 377 in octal and FF in hex, all the same number. The largest value a byte can hold is therefore 255, and 256 values in total from 0 to 255.

To convert a decimal number to binary by hand, subtract the largest power of two that fits and repeat. For 45: 32 fits (13 left), 16 does not, 8 fits (5 left), 4 fits (1 left), 2 does not, 1 fits, so 45 = 32 + 8 + 4 + 1 = 101101. Going the other way, add the powers of two where there is a 1. Hex works the same with powers of 16, which is why 0x2D = 2 × 16 + 13 = 45 matches.

Signed numbers use two’s complement. In 8 bits, 11111111 read as unsigned is 255 but read as signed is −1, and the signed range is −128 to 127. The same bit pattern means different things depending on how the program interprets it, a common source of bugs when data crosses between systems. Octal survives mostly in Unix file permissions: mode 755 means 7 (read, write, execute) for the owner and 5 (read, execute) for the group and everyone else.

Programming languages mark the base with a prefix, for example 0x for hex and 0b for binary in many languages, and a leading zero means octal in some, which can turn 010 into 8. For longer conversions, fractions, or arithmetic in other bases, the Number Converter, Binary Calculator and Hex Calculator on this site do the work and show the steps.

Put it into practice

The Number Systems tools on Utilities Bunker run the ideas from these guides on your own input — free, in your browser, with nothing uploaded.

See all 35 Number Systems tools →