How to Convert Binary to Decimal (and Decimal to Binary and Hex)

Add the powers of 2 where the bits are 1, or double as you read left to right. Reverse it by dividing by 2, and group bits in fours for hexadecimal.

To convert binary to decimal, multiply each bit by its place value, a power of 2, and add the results. Reading 101101 from right to left, the place values are 1, 2, 4, 8, 16 and 32, and the bits that are 1 sit under 32, 8, 4 and 1, so 101101₂ = 32 + 8 + 4 + 1 = 45. To go the other way, divide by 2 repeatedly and read the remainders from bottom to top.

Binary place values

Decimal uses powers of 10 (ones, tens, hundreds). Binary uses powers of 2, and each digit, called a bit, is either 0 or 1.

Position (from right) 7 6 5 4 3 2 1 0
Power of 2 2⁷ 2⁶ 2⁵ 2⁴ 2³ 2² 2¹ 2⁰
Value 128 64 32 16 8 4 2 1
N = bn × 2n + … + b1 × 2¹ + b0 × 2⁰

Memorizing the first eight values, 1 to 128, covers a full byte and makes most conversions quick.

Method 1: Add the place values

  1. Write the binary number.
  2. Under each bit, write its power of 2, starting with 1 on the right.
  3. Add the powers of 2 wherever the bit is 1.

11010110₂

Bits that are 1: 128, 64, 16, 4, 2

128 + 64 + 16 + 4 + 2 = 214

Method 2: Double and add (left to right)

This method needs no table. Start at 0, and for each bit from left to right, double the running total and add the bit.

101101₂: 0 → (0 × 2 + 1) = 1 → (1 × 2 + 0) = 2 → (2 × 2 + 1) = 5 → (5 × 2 + 1) = 11 → (11 × 2 + 0) = 22 → (22 × 2 + 1) = 45

It is fast for long binary strings and is how many computer routines parse numbers.

Decimal to binary: divide by 2

  1. Divide the number by 2 and write down the remainder (0 or 1).
  2. Divide the quotient by 2 again, recording the remainder.
  3. Repeat until the quotient is 0.
  4. Read the remainders from last to first.
Division Quotient Remainder
156 ÷ 2 78 0
78 ÷ 2 39 0
39 ÷ 2 19 1
19 ÷ 2 9 1
9 ÷ 2 4 1
4 ÷ 2 2 0
2 ÷ 2 1 0
1 ÷ 2 0 1

Reading upward: 156 = 10011100₂. Check: 128 + 16 + 8 + 4 = 156 ✓.

Alternative: subtract powers of 2. Find the largest power of 2 that fits (128), subtract it (156 − 128 = 28), and repeat with the remainder (16, then 8, then 4). Put a 1 in each position you used and 0 elsewhere.

Hexadecimal: binary in groups of four

Hexadecimal (base 16) uses digits 0–9 and A–F. Because 16 = 2⁴, each hex digit corresponds to exactly four bits, which makes conversion a lookup.

Decimal Binary Hex Decimal Binary Hex
0 0000 0 8 1000 8
1 0001 1 9 1001 9
2 0010 2 10 1010 A
3 0011 3 11 1011 B
4 0100 4 12 1100 C
5 0101 5 13 1101 D
6 0110 6 14 1110 E
7 0111 7 15 1111 F

10011100₂ → 1001 | 1100 → 9 | C → 9C₁₆

2F₁₆ → 0010 | 1111 → 101111₂ = 47

Hex to decimal works like binary, with powers of 16: 9C₁₆ = 9 × 16 + 12 = 156.

Web colors are three hex bytes for red, green and blue. #1E90FF is 1E = 30 red, 90 = 144 green and FF = 255 blue. The color converter translates between hex, RGB and other formats.

Octal (base 8) groups bits in threes. It survives mainly in Unix file permissions: 755₈ is 111 101 101, meaning read-write-execute for the owner and read-execute for everyone else.

The number base converter converts between binary, octal, decimal and hex, for any size of number.

Text is stored as numbers too. In ASCII and Unicode, the capital letter A is 65, or 01000001 in binary, and lowercase a is 97, or 01100001; the two differ by a single bit, worth 32. The text to ASCII converter shows the codes for any text, and the bitwise calculator applies AND, OR, XOR and shifts bit by bit.

How many values fit in n bits?

values = 2n   ·   largest unsigned value = 2n − 1
Bits Values Unsigned range Signed range (two’s complement)
4 16 0 to 15 −8 to 7
8 256 0 to 255 −128 to 127
16 65,536 0 to 65,535 −32,768 to 32,767
32 about 4.29 billion 0 to 4,294,967,295 −2,147,483,648 to 2,147,483,647

These limits explain many familiar numbers, from the 255 maximum in each color channel to the 2,147,483,647 ceiling of a signed 32-bit integer. The powers of 2 behind them are covered in exponent rules, and how they define kilobytes and gigabytes in data storage units explained.

Negative numbers: two’s complement

Computers store signed integers in two’s complement. The leftmost bit has a negative place value: in 8 bits, it is worth −128 instead of +128.

11111011₂ (8-bit signed) = −128 + 64 + 32 + 16 + 8 + 2 + 1 = −5

To negate a number, flip every bit and add 1: 5 = 00000101 → 11111010 → 11111011 = −5. The two’s complement calculator shows each step, and the binary calculator does arithmetic directly in base 2.

Binary fractions

Bits after the binary point are worth ½, ¼, ⅛ and so on. 0.101₂ = ½ + ⅛ = 0.625. Some simple decimals, such as 0.1, never terminate in binary (0.000110011…₂), just as 1/3 never terminates in decimal. That is why many programming languages report 0.1 + 0.2 as 0.30000000000000004 under the IEEE 754 floating-point standard. Financial software avoids the issue by counting in whole cents or using decimal number types.

Common mistakes

  • Starting place values from the left. The rightmost bit is always worth 1.
  • Reading division remainders top to bottom. Read them from the last remainder to the first.
  • Grouping hex digits from the left. Always group four bits starting from the right, padding the left with zeros.
  • Forgetting the sign bit when a value is meant to be signed.

Frequently asked questions

How do you convert binary to decimal?

Write the powers of 2 under the bits from right to left (1, 2, 4, 8, 16, …), then add the powers where the bit is 1. For 101101, that is 32 + 8 + 4 + 1 = 45.

How do you convert decimal to binary?

Divide the number by 2 repeatedly and record each remainder. Read the remainders from the last one to the first. For 156, the remainders from first to last are 0, 0, 1, 1, 1, 0, 0, 1, so 156 in binary is 10011100.

How do you convert binary to hexadecimal?

Group the bits into sets of four starting from the right, padding with zeros on the left if needed, and replace each group with its hex digit. 10011100 splits into 1001 and 1100, which are 9 and C, so it is 9C in hex.

What is the largest number you can store in 8 bits?

255, which is 11111111 in binary, or 2⁸ − 1. Eight bits can represent 256 different values, 0 through 255. With 16 bits the maximum is 65,535, and with 32 bits it is 4,294,967,295.

Why does 0.1 + 0.2 not equal 0.3 in many programming languages?

Because 0.1 and 0.2 have no exact binary representation, just as 1/3 has no exact decimal one. Computers store the closest binary fraction, and the tiny errors add up, so 0.1 + 0.2 evaluates to 0.30000000000000004 in standard double-precision floating point.