Skip to content
mathbehind

Binary, Octal and Hexadecimal: How Number Bases Work

Every number base works the same way; only the number of digits changes. Here is how to read binary and hex, with worked conversions.

By Muhammad Ahmad. Published . 2 min read.

Want to run your own numbers?Number Base ConverterOpen the calculator

Decimal feels natural because we learn it first, but it is just one way of writing numbers. Computers store everything in binary, and programmers use hexadecimal as a compact way to write it. Once you see the pattern, converting between them is straightforward.

Place value

In decimal, each position is worth ten times the one to its right: ones, tens, hundreds. The number 2026 means 2 thousands, 0 hundreds, 2 tens and 6 ones.

Other bases work exactly the same way, with a different multiplier. In binary (base 2) each position is worth twice the one to its right. In hexadecimal (base 16) each position is worth 16 times the one to its right.

Reading hexadecimal

Hex needs 16 digit symbols, so after 0 to 9 it uses A to F for 10 to 15. To read a hex number, multiply each digit by its place value and add them up.

7EA in hexadecimal
  1. 7 in the 256s place

    7 × 256equals1,792

  2. E (14) in the 16s place

    14 × 16equals224

  3. A (10) in the ones place

    10 × 1equals10

  4. Total

    1,792 + 224 + 10equals2,026

So 7EA in hex is 2026 in decimal. In binary it is 11111101010, and in octal (base 8) it is 3752.

Why hex is everywhere

Each hex digit stands for exactly four binary digits, so one byte (8 bits) is always exactly two hex digits. The largest byte value, 11111111 in binary, is FF in hex and 255 in decimal. That is why colour codes like #07804F, memory addresses and file signatures are written in hex: it is short, and it maps cleanly onto the underlying bits.

Quick reference

  • Binary 1010 = hex A = decimal 10
  • Binary 1111 = hex F = decimal 15
  • Binary 10000 = hex 10 = decimal 16
  • Binary 11111111 = hex FF = decimal 255

Octal is less common today, but you will still see it in Unix file permissions, where 755 means read, write and execute for the owner and read and execute for everyone else.

Tip: To convert binary to hex by hand, split the binary number into groups of four from the right, and convert each group to a single hex digit.