Skip to content
GEEKnodes

Computing

Binary, Hexadecimal and Decimal: Converter and How They Work

Convert numbers between decimal, binary, hexadecimal and octal. How each base works, converting by hand and where you will see them: web colors, MAC and IP addresses.

Computers only understand zeros and ones, but we humans find decimal more convenient, and programmers prefer hexadecimal. Here you have a converter and a simple explanation of how each system works and how to go from one to another by hand.

In short

  • Binary (base 2): only 0 and 1. It’s what the hardware uses.
  • Hexadecimal (base 16): 0–9 and A–F. Each digit equals exactly 4 bits.
  • A byte is 8 bits: 0 to 255 in decimal, 00 to FF in hexadecimal.

Converter

Type in any field and the others update. It handles large numbers.

How a number base works

In decimal, each position is worth 10 times more than the one to its right: in 352, the 3 is worth 300, the 5 is worth 50 and the 2 is worth 2.

Comparison of place value in decimal, binary and hexadecimal with their expanded sums.
Each position multiplies the digit by a power of its base.

The other bases work the same way; only the multiplier changes:

BaseDigitsValue of each position (right to left)
2 (binary)0 11, 2, 4, 8, 16, 32, 64, 128…
8 (octal)0–71, 8, 64, 512…
10 (decimal)0–91, 10, 100, 1,000…
16 (hexadecimal)0–9, A–F1, 16, 256, 4,096…

In hexadecimal, A = 10, B = 11, C = 12, D = 13, E = 14 and F = 15.

Converting by hand

From binary to decimal

Add up the value of each position that has a 1. For 1011 0110:

128  64  32  16   8   4   2   1
  1   0   1   1   0   1   1   0
128 + 32 + 16 + 4 + 2 = 182
The bits of 1011 0110 line up with their weights and add up to 182 in decimal.
We only add the weights of the positions that contain a 1.

From decimal to binary

Divide by 2 over and over and write down the remainders; they’re read from bottom to top. For 13:

13 / 2 = 6  remainder 1
 6 / 2 = 3  remainder 0
 3 / 2 = 1  remainder 1
 1 / 2 = 0  remainder 1
→ 1101

From binary to hexadecimal (the 4-bit trick)

Group the bits in fours starting from the right and convert each group:

1011 0110
  B    6   → 0xB6
The binary groups 1011 and 0110 become the hexadecimal digits B and 6.
Each group of four bits equals one hexadecimal digit.

That’s why hexadecimal is so handy: a byte is always two hexadecimal digits.

Where you’ll see them

WhereExampleWhat it means
Web colors#0A66B8Red 0A (10), green 66 (102), blue B8 (184)
MAC address3C:22:FB:1A:09:7E6 bytes in hexadecimal
IPv4 address192.168.1.14 bytes written in decimal
IPv6 addressfe80::116 bytes in hexadecimal
I2C addresses0x27The module at 39 in decimal
Linux permissionschmod 755Octal: rwx r-x r-x

Prefixes that indicate the base

To avoid confusing 10 in decimal with 10 in binary, programming uses prefixes:

  • 0b1010 → binary (10 in decimal).
  • 0x1A → hexadecimal (26 in decimal).
  • 0o17 or 017 → octal (15 in decimal).

Common mistakes

  • Confusing the letter O with zero in hexadecimal: the valid digits are 0–9 and A–F.
  • Forgetting the reading order when converting from decimal to binary: the remainders are read from bottom to top.
  • Thinking colors go from 0 to 100: each channel goes from 00 to FF, that is, from 0 to 255.
  • Miscounting bits: 8 bits = 1 byte; 4 bits = 1 hexadecimal digit (a nibble).

Accessibility preferences

Quick profiles

Text and reading

Text size
Default
Line height
Default
Letter spacing
Default
Word spacing
Default

Colour

Motion and orientation

Cursor