Calcylator
Binary To Decimal

Binary to decimal:
reading ones and zeros as an ordinary number

Place values, a left-to-right doubling method that needs no powers table, and where these conversions show up in networking and code.

Calcylator Editorial Team

Updated · 5 min read

Positions are powers of two

In decimal, each position to the left is worth ten times the one before it: ones, tens, hundreds. Binary uses the same idea with two. The rightmost digit is worth 1, the next 2, then 4, 8, 16, 32, and so on, doubling each time. A binary digit, called a bit, can only be 0 or 1, and it says whether that place value is counted.

So to convert, write the place values under the digits, and add up the ones that sit under a 1. Reading from the right, the first position is position 0, because 2⁰ = 1, which is why the exponent is always one less than the position number.

Binary to decimal =Σ (bitᵢ × 2ⁱ)
bitᵢ:
the digit, 0 or 1, at position i
i:
position counted from the right, starting at 0
Σ:
add the results for every position

A full worked conversion

  • Binary number

    101101

  • Number of digits

    6, so the leftmost place value is 2⁵ = 32

  • Place values

    32, 16, 8, 4, 2, 1

  • Digits under them

    1, 0, 1, 1, 0, 1

  • Sum of the 1s

    32 + 8 + 4 + 1

Decimal value

45

Check by going back: 45 = 32 + 13, 13 = 8 + 5, 5 = 4 + 1, which gives 101101.

A table helps when the number is longer, because you can see which positions are active without losing track of the exponent.

101101 laid out by position
Place value32168421
Bit101101
Counted3208401

Adding the bottom row, 32 + 0 + 8 + 4 + 0 + 1, gives 45. The zeros contribute nothing, so you can simply skip them.

The doubling shortcut for long numbers

A longer string is awkward with a table of powers. A faster approach reads from the left, doubling the running total and adding the next bit. Start at zero. For each digit, double what you have and then add the digit.

  1. Digit 1: double 0 and add 1, giving 1.
  2. Digit 0: double 1 and add 0, giving 2.
  3. Digit 1: double 2 and add 1, giving 5.
  4. Digit 1: double 5 and add 1, giving 11.
  5. Digit 0: double 11 and add 0, giving 22.
  6. Digit 1: double 22 and add 1, giving 45.

The result is again 45. The advantage of this method is that you never have to remember 2⁹ or 2¹¹. It also matches how a computer processes a stream of bits as it arrives, one at a time.

How big a number fits in so many bits

The largest value that fits in n bits is 2ⁿ − 1, which is all ones. Eight bits, a byte, reach 255, and sixteen bits reach 65,535. A binary number with a given number of digits can be sized up quickly this way.

Range by bit length
BitsLargest valueTypical use
415A single hexadecimal digit
8255One byte, one IP address octet, one colour channel
101,023Common ADC resolution
1665,535Network ports
324,294,967,295IPv4 addresses, counters

Leading zeros do not change the value. 00101101 is still 45; they only show that the value is stored in 8 bits. When you compare two binary numbers of different lengths, compare after padding the shorter one on the left.

A practical case: reading an IP address

IPv4 addresses are four 8-bit numbers separated by dots, so each octet is converted on its own. The address 11000000.10101000.00000001.00000001 can be read octet by octet.

  • 11000000 = 128 + 64 = 192
  • 10101000 = 128 + 32 + 8 = 168
  • 00000001 = 1
  • 00000001 = 1

Together they give 192.168.1.1, the familiar default address of many home routers. Subnet masks work the same way: 11111111.11111111.11111111.00000000 is 255.255.255.0, where the 24 leading ones are the '/24' in network notation.

Common errors and how to catch them

  • Counting positions from the left instead of the right, which gives numbers that are wrong by large factors.
  • Starting the exponent at 1 rather than 0, so every value is doubled.
  • Treating a digit other than 0 or 1 as valid; a '2' means the number was not binary.
  • Forgetting that a byte may be a signed number. In two's complement, 11111111 is −1, not 255, and the leftmost bit carries a negative weight of −128.
  • Dropping the leading bit in a long number when copying it by hand.

A fast check is the last digit: if it is 1 the decimal number is odd, if 0 it is even. 101101 ends in 1, and 45 is odd. A binary-to-decimal calculator is handy for numbers beyond 16 bits, but the method is the same.

Shortcuts: hexadecimal groups and code

Hexadecimal gives a way to avoid long strings. Split the binary number into groups of four from the right and convert each group, since 4 bits are exactly one hex digit. 101101 becomes 0010 1101, which is 2 and 13 (written D), so 0x2D. Then 2 × 16 + 13 = 45 again, a useful second check on a hand conversion.

Programming languages do the conversion for you, which is a good way to verify a hand calculation. In Python, int('101101', 2) returns 45, and in JavaScript parseInt('101101', 2) does the same. A literal written with the 0b prefix, such as 0b101101, is read as 45 directly. The second argument matters: leaving it out makes the function treat the text as an ordinary decimal number, and you would get 101,101 rather than 45.

It is also worth memorising a few anchors: 2⁴ = 16, 2⁸ = 256 and 2¹⁰ = 1,024. With those you can estimate any binary number by its length. A 10-digit binary number, for example, is between 512 and 1,023, which helps you spot a conversion that has gone badly wrong.

Fractions after the point

Binary fractions use negative powers of two: the first digit after the point is worth ½, the next ¼, then ⅛. The value 0.101 in binary is 1 × ½ + 0 × ¼ + 1 × ⅛ = 0.625. This is also why 0.1 in decimal cannot be written exactly in binary, which explains tiny rounding differences in many programming languages.

Common questions

How do you convert binary to decimal?

Write the place values 1, 2, 4, 8, 16 and so on from the right, and add the values wherever the binary digit is 1. For 101101 that is 32 + 8 + 4 + 1 = 45.

What is 11111111 in decimal?

Eight ones add up to 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255, which is 2⁸ − 1. It is the largest value that fits in one byte, and also the maximum value of an IP address octet.

What is the quickest way to convert a long binary number?

Use doubling from the left: start at 0, double the total for each digit, then add that digit. For 101101 the running totals are 1, 2, 5, 11, 22, 45, so you reach 45 without needing a table of powers.

Why does binary only use 0 and 1?

Digital circuits have two reliable states, on and off, so each bit stores one of two values. Place value then works with powers of two, the way decimal works with powers of ten.

Was this guide helpful?

Continue reading

View all blogs