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.
| Position | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|
| Power | 2⁷ | 2⁶ | 2⁵ | 2⁴ | 2³ | 2² | 2¹ | 2⁰ |
| Place value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
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
| Bit | 1 | 1 | 0 | 1 | 0 | 1 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|
| Place value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
| Counts? | 128 | 64 | – | 16 | – | 4 | 2 | – |
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
| Bit | Calculation | Running total |
|---|---|---|
| 1 | 0 × 2 + 1 | 1 |
| 1 | 1 × 2 + 1 | 3 |
| 0 | 3 × 2 + 0 | 6 |
| 1 | 6 × 2 + 1 | 13 |
| 0 | 13 × 2 + 0 | 26 |
| 1 | 26 × 2 + 1 | 53 |
| 1 | 53 × 2 + 1 | 107 |
| 0 | 107 × 2 + 0 | 214 |
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→D6→ hexD6→ 13 × 16 + 6 = 21411 010 110→326→ octal326→ 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 | × 2 | Bit | Fraction left |
|---|---|---|---|
| 1 | 0.2 | 0 | 0.2 |
| 2 | 0.4 | 0 | 0.4 |
| 3 | 0.8 | 0 | 0.8 |
| 4 | 1.6 | 1 | 0.6 |
| 5 | 1.2 | 1 | 0.2 |
| 6 | 0.4 | 0 | 0.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.
1001is 9;101is 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 reads1010and stops at the2without an error (MDN). The converter reports"2" at position 5 is not a base-2 digitinstead. - 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.
| Binary | Decimal | Hex | Octal |
|---|---|---|---|
1010 | 10 | A | 12 |
1111 | 15 | F | 17 |
10000 | 16 | 10 | 20 |
101101 | 45 | 2D | 55 |
1100100 | 100 | 64 | 144 |
11010110 | 214 | D6 | 326 |
11111111 | 255 | FF | 377 |
100000000 | 256 | 100 | 400 |
1111101000 | 1000 | 3E8 | 1750 |
10011100010000 | 10000 | 2710 | 23420 |
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.