To convert a binary number to decimal, give each bit a place value (1, 2, 4, 8 and so on from the right), then add the place values of the bits that are 1. 11010110 has 1s in the 128, 64, 16, 4 and 2 places, so it is 128 + 64 + 16 + 4 + 2 = 214.

This guide works through that method, a faster one for long numbers, the reverse direction, fractions and negative numbers. Every result below was also checked with the Binary to Decimal & Hex Converter, and the step listings are its “Show the working” output.

Place values: the one idea behind every conversion

In any positional system, a digit is worth its face value times the base raised to the power of its position. Positions are counted from 0, starting at the rightmost digit. In decimal, 352 is 3 × 10² + 5 × 10¹ + 2 × 10⁰. Binary works the same way with base 2, and because a binary digit is only 0 or 1, each position either adds its whole place value or adds nothing.

Position76543210
Power2⁷2⁶2⁵2⁴2³2²2¹2⁰
Place value1286432168421

It helps to know the powers of two up to 2¹⁰ = 1024 by heart. Two more are worth remembering: 2¹⁶ = 65,536 (the number of values in 16 bits) and 2³² = 4,294,967,296 (the number of values in 32 bits).

Method 1: add the place values

Write the place values above the bits, keep the ones under a 1, and add them up.

Example: 11010110

Bit11010110
Place value1286432168421
Counts?12864–16–42–

128 + 64 + 16 + 4 + 2 = 214. The converter writes the same sum like this:

Positional expansion, base 2 to decimal:
  1 × 2^7 = 128
  1 × 2^6 = 64
  0 × 2^5 = 0
  1 × 2^4 = 16
  0 × 2^3 = 0
  1 × 2^2 = 4
  1 × 2^1 = 2
  0 × 2^0 = 0
  Sum = 214

Example: 101101 has six bits, so the leftmost bit is worth 2⁵ = 32, not 128. The 1s are in the 32, 8, 4 and 1 places: 32 + 8 + 4 + 1 = 45. Always start the place values from the right end. Counting from the left is the most common way to get a wrong answer.

This method is easy to check, because each term is visible. For numbers longer than about 10 bits it gets slow, because you need the large powers of two.

Method 2: doubling from the left

The doubling method (Horner’s method) needs no table of powers. Start with 0. For each bit from left to right, double the running total and add the bit.

Example: 11010110 again

BitCalculationRunning total
10 × 2 + 11
11 × 2 + 13
03 × 2 + 06
16 × 2 + 113
013 × 2 + 026
126 × 2 + 153
153 × 2 + 1107
0107 × 2 + 0214

It works because each doubling shifts every bit read so far one place to the left, which is the same as multiplying it by 2. After the last bit, the first bit has been doubled seven times and is worth 2⁷ = 128, as in Method 1.

Doubling is the better choice for long numbers and for mental arithmetic. It is also the loop most hand-written parsers use: multiply the total by the base, add the next digit.

Going back: decimal to binary by repeated division

To convert decimal to binary, divide by 2 and write down the remainder. Repeat with the quotient until it is 0. The remainders, read from the last one to the first, are the binary digits. This is the converter’s working for 214:

Repeated division, decimal to base 2:
  214 ÷ 2 = 107, remainder 0
  107 ÷ 2 = 53, remainder 1
  53 ÷ 2 = 26, remainder 1
  26 ÷ 2 = 13, remainder 0
  13 ÷ 2 = 6, remainder 1
  6 ÷ 2 = 3, remainder 0
  3 ÷ 2 = 1, remainder 1
  1 ÷ 2 = 0, remainder 1
  Remainders read from bottom to top: 11010110

The first remainder is the rightmost bit. If you write the remainders in the order you get them, you get 01101011, which is the answer reversed.

There is also a subtraction method. Find the largest power of two that fits, subtract it, and repeat: 214 − 128 = 86, 86 − 64 = 22, 22 − 16 = 6, 6 − 4 = 2, 2 − 2 = 0. The powers used were 128, 64, 16, 4 and 2, so those places get a 1. This is Method 1 in reverse, and it is usually faster in your head for numbers under 1,000.

Shortcuts through hexadecimal and octal

One hex digit is exactly four bits, and one octal digit is exactly three bits. To convert a long binary number, you can group the bits from the right, convert each group with a small table, and convert the hex result to decimal if you still need it.

  • 1101 0110 → D 6 → hex D6 → 13 × 16 + 6 = 214
  • 11 010 110 → 3 2 6 → octal 326 → 3 × 64 + 2 × 8 + 6 = 214

This is why programmers write bit patterns in hex: 0xD6 is easier to read than 0b11010110, and each digit maps back to four bits without any arithmetic.

Binary fractions

Bits to the right of the binary point have the place values ½, ¼, ⅛ and so on (2⁻¹, 2⁻², 2⁻³). 101.101 is 4 + 1 + ½ + ⅛ = 5.625. In the same way, 1010.011 is 8 + 2 + ¼ + ⅛ = 10.375.

To go from a decimal fraction to binary, multiply the fraction by 2. The whole-number part of the result is the next bit. Keep the fraction and repeat. For 0.1:

Step× 2BitFraction left
10.200.2
20.400.4
30.800.8
41.610.6
51.210.2
60.400.4

At step 5 the leftover fraction is 0.2 again, which was the leftover after step 1. From there, the bits repeat. So 0.1 in binary is 0.0 followed by 0011 forever. The converter writes this as 0.0(0011), and 0.3 as 0.0(1001). A decimal fraction ends in binary only if its denominator, in lowest terms, is a power of two. 0.625 = 5/8 ends; 0.1 = 1/10 does not.

That is also why 0.1 + 0.2 gives 0.30000000000000004 in JavaScript. A JavaScript number is an IEEE 754 double (MDN) and stores 53 significant bits, so the repeating pattern is cut and rounded.

Negative numbers: two’s complement

A bit pattern alone does not say whether it is signed. 11010110 is 214 as an unsigned 8-bit number. As a signed 8-bit number in two’s complement, the top bit has the place value −128 instead of +128:

−128 + 64 + 16 + 4 + 2 = −42

An equivalent rule: if the top bit is 1, convert as unsigned and subtract 2ⁿ, where n is the number of bits. 214 − 256 = −42.

To write a negative decimal number in two’s complement, write the positive number in n bits, invert every bit, and add 1. For −42 in 8 bits: 42 = 00101010, inverted 11010101, plus 1 = 11010110. In the converter, type -42, set Two’s complement to 8-bit and read 11010110 (hex D6). To decode a pattern, type it, choose the width and tick “Read input as signed”: 11010110 reads as −42.

The width matters. 11010110 is −42 in 8 bits but 214 in 16 bits, because a 16-bit pattern for 214 is 0000000011010110 and its top bit is 0.

Mistakes that give the wrong answer

  • Starting the place values from the left. The rightmost bit is always worth 1. A 6-bit number starts at 32, not 128.
  • Reading the division remainders top to bottom. The first remainder is the last bit.
  • Dropping a zero inside the number. 1001 is 9; 101 is 5. Group bits in fours (1101 0110) when you copy them.
  • Treating a signed pattern as unsigned, or the reverse. Decide the width and the signedness before you convert.
  • Trusting a parser that stops at bad input. JavaScript’s parseInt('10102', 2) returns 10: it reads 1010 and stops at the 2 without an error (MDN). The converter reports "2" at position 5 is not a base-2 digit instead.
  • Converting large values with floating-point numbers. JavaScript numbers hold integers exactly only up to 2⁵³ − 1 (MDN). Sixty 1-bits are 1,152,921,504,606,846,975, but parseInt('1'.repeat(60), 2) gives 1152921504606847000.

Checking an answer with Python, JavaScript or the converter

Python reads a binary string with int(s, 2), and its integers have no size limit. Underscores between digits are allowed, as in code literals (Python docs):

int('11010110', 2)        # 214
int('1101_0110', 2)       # 214
int('0b11010110', 2)      # 214, the prefix is allowed with base 2
format(214, 'b')          # '11010110'
format(214, '_b')         # '1101_0110'
int('11010110', 2) - 256  # -42, the signed 8-bit reading

In JavaScript, use BigInt for anything that might exceed 2⁵³:

BigInt('0b11010110');               // 214n
(214).toString(2);                  // '11010110'
BigInt.asIntN(8, 214n);             // -42n, the signed 8-bit reading
BigInt('0b' + '1'.repeat(60));      // 1152921504606846975n

Python’s int() has one limit of its own: by default it refuses decimal strings of more than 4,300 digits, to avoid very slow conversions (Python docs). Power-of-two bases such as binary and hex are not limited.

The converter accepts up to 20,000 digits in any base from 2 to 36, ignores spaces and underscores between digits, and shows the place-value sum and the division steps for numbers up to 64 digits.

Practice table

Cover the right-hand columns and convert each binary number with either method. All values were checked with Python’s int(s, 2) and the converter.

BinaryDecimalHexOctal
101010A12
111115F17
10000161020
101101452D55
110010010064144
11010110214D6326
11111111255FF377
100000000256100400
111110100010003E81750
1001110001000010000271023420

Two patterns stand out. A run of n ones is 2ⁿ − 1 (11111111 = 255), and a 1 followed by n zeros is 2ⁿ (100000000 = 256). If you can spot those, you can check many answers at a glance.

For converting text to binary instead of numbers, see the Text to Binary Translator.