Positional notation
Every base works the same way: each digit is multiplied by the base raised to its position. In base 10, 345 means 3×100 + 4×10 + 5. In base 2 the same digits mean 3×4 + 4×2 + 5 — except that base 2 only has the digits 0 and 1, so 345 is not a valid binary number.
binary 1 0 1 1
place value 8 4 2 1
= 8 + 0 + 2 + 1 = 11 (decimal)
The four bases you meet daily
- Binary (base 2) — how hardware stores values. Digits: 0–1.
- Octal (base 8) — digits 0–7. Still used for Unix file permissions, e.g.
755. - Decimal (base 10) — everyday arithmetic. Digits 0–9.
- Hexadecimal (base 16) — digits 0–9 plus A–F. Compact shorthand for binary, since one hex digit equals exactly four bits.
Prefixes in source code
0b1011 binary = 11
0o755 octal = 493
755 decimal = 755 (no prefix!)
0x2F hexadecimal = 47
Watch out for leading zeros in older code: some languages historically treated 0755 as octal. Modern JavaScript uses 0o to remove that ambiguity.
Why hex is everywhere
Because four bits map cleanly to one hex digit, a byte (eight bits) is always exactly two hex digits. That makes hex a compact, lossless view of raw memory — used in colour codes (#FF8800 is three bytes: red, green, blue), memory addresses, character encodings and network protocols.
Bytes and their range
One byte holds 256 values: 0x00 to 0xFF, or 0 to 255 in decimal. Unsigned values stop at 255. Signed values split the range in half, using two’s complement: the top bit indicates a negative number, so 0xFF means -1 in a signed byte.
When a conversion result looks wrong, check the sign convention and the assumed word size — 8, 16, 32 or 64 bits. Most "the converter is broken" reports are actually width mismatches.
Converting in both directions
Two procedures cover almost every manual conversion. To go from decimal to another base, divide repeatedly by the target base and read the remainders from bottom to top. To go the other way, multiply each digit by the base raised to its position and add the results.
13 to binary
13 ÷ 2 = 6 remainder 1 (least significant)
6 ÷ 2 = 3 remainder 0
3 ÷ 2 = 1 remainder 1
1 ÷ 2 = 0 remainder 1 (most significant)
read upwards: 1101
0x2F to decimal
2 × 16 + 15 = 32 + 15 = 47
The remainder method also gives quick sanity checks: a decimal number is even exactly when its last binary digit is 0, and a hexadecimal value is a multiple of 16 exactly when its last hex digit is 0.
Bits, nibbles, bytes and words
A single bit is one binary digit. Four bits form a nibble, which is exactly one hex digit. Eight bits form a byte, or two hex digits. Grouping from the right is essential: 10110111 splits into 1011 0111, which is 0xB7. Grouping from the left produces a different and wrong answer, and it is one of the most common hand-conversion mistakes.
The same idea scales up. A 16-bit word is four hex digits, a 32-bit word is eight, and a 64-bit word is sixteen. That is why a memory dump, a MAC address and a UUID all look like tidy rows of hexadecimal pairs: each pair is one byte, read left to right in the order the system stores them.
Reading byte dumps and endianness
When a debugger or hex editor shows a row of bytes such as 48 65 6C 6C 6F, each pair is one byte and the sequence spells “Hello” in ASCII. Multi-byte numbers are another matter: a 32-bit integer can be written most-significant byte first (big-endian) or least-significant first (little-endian). The same four bytes mean different numbers under the two conventions, so a byte dump is only meaningful together with its endianness.
Common mistakes and edge cases
- Confusing a value with its text. The decimal string
11and the binary string11are different numbers; the base is part of the meaning. - Assuming a prefix is optional. In JavaScript
parseInt("0x2F")works, butparseInt("2F")returns 47 only when you pass 16 as the second argument. Always pass the radix explicitly. - Trusting leading zeros. A leading zero does not change the value in most modern languages, but in older C-style code it can switch the literal to octal, so
0755may not be the decimal 755 you expected. - Mixing case in hex.
0xffand0xFFare the same value; hex digits are case-insensitive, although style guides standardise on one form for readability. - Forgetting signed ranges. An 8-bit signed value spans -128 to 127, not 0 to 255. Reading
0xFFas 255 or as -1 depends entirely on the convention in use. - Losing precision on large IDs. JavaScript numbers are doubles, so integers above 253 lose precision. Parse 64-bit identifiers as
BigIntor as strings, not as ordinary numbers.
Which base to use where
| Base | Digits | Bits per digit | Typical use |
|---|---|---|---|
| Binary (2) | 0–1 | 1 | Bit flags, masks, hardware state |
| Octal (8) | 0–7 | 3 | Unix permissions, some legacy protocols |
| Decimal (10) | 0–9 | ~3.32 | Everyday values, user input, statistics |
| Hexadecimal (16) | 0–9, A–F | 4 | Colours, addresses, UUIDs, hashes, byte dumps |
Where these bases appear in practice
Hex shows up wherever bytes need to be readable: colour codes such as #FF8800, memory addresses, MAC addresses, cryptographic hashes and UUID strings. Four bits per digit means a 32-character UUID is a compact, lossless rendering of 128 bits of data. Binary is the right notation when individual flags matter, because each position maps to one true-or-false condition.
Octal survives mainly in file permissions, where 755 means read-write-execute for the owner and read-execute for group and others. Reading it as decimal is a frequent error: decimal 755 is 1363 in octal, a completely different permission set.
Practical checklist
- State the base explicitly whenever a value leaves your program; the
0x,0band0oprefixes are unambiguous. - Group binary digits in fours from the right before converting to hex, and in threes for octal.
- Check the expected width and signedness before reading a converted value.
- Use a converter for anything longer than a few digits; manual arithmetic is where off-by-one errors appear.
Convert any direction with our Number Base Converter, which shows binary, octal, decimal and hex side by side. See HEX, RGB and HSL for the most common place hex meets everyday work.