What is a number base (a positional number system)?
In a number system the value of each digit depends on the position it occupies and on the system's base (radix). In the decimal system the number 243 actually means (2×100) + (4×10) + (3×1); moving from right to left, each digit is multiplied by increasing powers of the base (1, 10, 100, ...) and the results are added. This general rule — positional notation — works exactly the same way for base 2, 8 or 16 as it does for base 10; the only differences are how many digits are available and the base of the power each position represents.
Decimal is the human number system we use in daily life, made up of the 10 digits 0-9; it is thought to derive from counting on ten fingers. Computers, on the other hand, store data in a different base, binary — we explain why in the next section.
Binary: the language of computers
Binary uses base 2 and directly reflects how computers store data at the hardware level: each bit (binary digit — 0 or 1) represents a power of 2. Because a transistor or a memory cell can reliably distinguish only two states (current present/absent, high/low voltage), the fundamental data unit of computers is expressed in binary.
A group of eight bits forms a byte and can represent 256 different values, that is, a number from 0 to 255 (2 to the power of 8 is 256). The value 255 (binary: 11111111), the default example in KEYDAL's number base converter, shows exactly this upper limit — it is the largest value reached when all eight bits are 1.
Octal and its place in file permissions
Octal uses base 8; it was common in early Unix systems and today we still meet it most often in file permission notation. The reason is that a file permission (read, write, execute) is expressed as a group of three bits, and each three-bit group corresponds to exactly one octal digit (0-7) — which makes it possible to write permissions as compact, single-digit octal numbers instead of individual bits.
755 is octal notation; it grants read-write-execute to the owner (7 = 111) and read-execute to the group and to other users (5 = 101).
chmod 644 index.htmlHexadecimal: compact byte notation
Hexadecimal uses base 16 and is widely preferred in programming, because each hex digit corresponds to exactly 4 binary bits (a nibble) — which makes binary data compact and readable. That is why memory addresses, colour codes such as #FF5733, MAC addresses and hash digests are shown in hex: two hex digits express exactly one byte (8 bits).
Because 16 different digits are needed (0-9 is not enough), the values from 10 to 15 are shown as letters: A=10, B=11, C=12, D=13, E=14, F=15. With two hex digits you can therefore write every value a single byte can take, from 00 to FF (0 to 255).
| Decimal | Binary (4 bits) | Octal | Hexadecimal |
|---|---|---|---|
| 0 | 0000 | 0 | 0 |
| 1 | 0001 | 1 | 1 |
| 2 | 0010 | 2 | 2 |
| 3 | 0011 | 3 | 3 |
| 4 | 0100 | 4 | 4 |
| 5 | 0101 | 5 | 5 |
| 6 | 0110 | 6 | 6 |
| 7 | 0111 | 7 | 7 |
| 8 | 1000 | 10 | 8 |
| 9 | 1001 | 11 | 9 |
| 10 | 1010 | 12 | A |
| 11 | 1011 | 13 | B |
| 12 | 1100 | 14 | C |
| 13 | 1101 | 15 | D |
| 14 | 1110 | 16 | E |
| 15 | 1111 | 17 | F |
Converting bases by hand: a step-by-step example and common mistakes
To convert the decimal number 202 to binary, we divide the number by 2 repeatedly and note the remainders: 202÷2=101 remainder 0, 101÷2=50 remainder 1, 50÷2=25 remainder 0, 25÷2=12 remainder 1, 12÷2=6 remainder 0, 6÷2=3 remainder 0, 3÷2=1 remainder 1, 1÷2=0 remainder 1. Reading the remainders from the last to the first (bottom to top), the result is 11001010.
To convert the same number to hexadecimal, we divide by 16 instead: 202÷16=12 remainder 10 (A), 12÷16=0 remainder 12 (C). Reading the remainders in reverse order gives CA. If you want to verify the result, you can work backwards: in the number 11001010, match only the positions that hold a 1 with the powers of 2 from right to left (1, 2, 4, 8, 16, 32, 64, 128) and add them: 128 + 64 + 8 + 2 = 202.
- Counting bit positions incorrectly: when decoding a binary number, the rightmost digit always carries 2 to the power of 0 (that is, 1), the one to its left represents 2, the next one 4, and so on, doubling each time. Getting confused about which direction to count the positions leads you to compute the wrong decimal value.
- Skipping or mixing up the 0x and 0b prefixes: in code, the
0xprefix indicates a number should be read as hexadecimal and the0bprefix as binary. A bare value such as 10, written with no prefix, can mean decimal 10, binary 2 or hexadecimal 16 depending on context — a number shared without stating which base it is written in is open to being interpreted in the wrong base. - Confusing octal and hexadecimal digits: an octal digit can only take a value from 0 to 7, while a hexadecimal digit can take 16 values, 0-9 and A-F. The digits 8 or 9 never appear in an octal number, and a letter from G onwards never appears in a hexadecimal one; if such a digit is present, the value entered is invalid for that base.
- Trying to read long values without grouping them: reading a long hexadecimal or binary value such as a colour code or MAC address as a single block, without separating the digits into groups of two (hex) or eight (a binary byte), makes it hard to follow which part represents which byte and leads to copying mistakes.
Practise with the KEYDAL Number Base Converter
Knowing how to convert the four bases by hand is useful, but in daily use you need a converter for speed and accuracy. KEYDAL's number base converter has four separate fields, for binary, octal, decimal and hexadecimal; when you type a value into any one of them, the other three update instantly, so you can see all four conversions on a single screen and check the calculation you did by hand.