Number systems

Binary to Decimal Converter

Type a binary number to convert it to decimal instantly, with the step-by-step working: each bit, its place value and the sum. It also shows the hex and octal values, and works for long binary numbers too.

Binary number to Decimal number converter

Decimal number
0

Step by step

How to convert binary to decimal

Binary is base 2: every position is worth twice the position to its right. Reading from the right, the places are worth 1, 2, 4, 8, 16 and so on (20, 21, 22, ...). To convert:

  1. Write the place value above each bit, starting with 1 at the rightmost bit and doubling as you move left.
  2. Keep the place values that have a 1 under them and ignore the ones with a 0.
  3. Add the kept place values. The total is the decimal number.

Example: 101101 in decimal. The bits from left to right sit on the places 32, 16, 8, 4, 2, 1. The 1s are on 32, 8, 4 and 1, so 101101 = 32 + 8 + 4 + 1 = 45.

Place value32168421
Bit101101
Adds3208401

A shortcut (doubling): start at 0, and for each bit from left to right, double the total and add the bit. For 1011: 0×2+1 = 1, 1×2+0 = 2, 2×2+1 = 5, 5×2+1 = 11. This is also how the code below works.

Binary to decimal table

BinaryDecimalBinaryDecimal
0000010008
0001110019
00102101010
00113101111
01004110012
01015110113
01106111014
01117111115
Power of 2BinaryDecimal
2011
21102
221004
2310008
241000016
2510000032
26100000064
2710000000128
28100000000256
210100000000001,024

One byte is 8 bits, so it holds 00000000 to 11111111, which is 0 to 255 in decimal (28 = 256 values). Need octal or hex too? Use the Number Base Converter. Studying for AP Computer Science Principles? Binary numbers are part of Big Idea 2, and the AP CSP practice test has questions on them.

Convert binary to decimal in code

Most languages have a built-in for this, and the loop is short enough to write yourself. Press Run this code to try each one in the online editor.

Python

binary_to_decimal.py Run this code
# Built-in: int() with base 2
print(int("101101", 2))  # 45

# By hand: double the total and add each bit
def binary_to_decimal(bits):
    total = 0
    for bit in bits:
        total = total * 2 + int(bit)
    return total

for bits in ["1011", "11111111", "100000000"]:
    print(bits, "=", binary_to_decimal(bits))

C

binary_to_decimal.c Run this code
#include <stdio.h>

long binary_to_decimal(const char *bits) {
    long total = 0;
    for (int i = 0; bits[i] != '\0'; i++) {
        total = total * 2 + (bits[i] - '0');
    }
    return total;
}

int main(void) {
    printf("%ld\n", binary_to_decimal("101101"));   /* 45 */
    printf("%ld\n", binary_to_decimal("11111111")); /* 255 */
    return 0;
}

JavaScript

binaryToDecimal.js Run this code
// Built-in: parseInt with radix 2
console.log(parseInt("101101", 2)); // 45

// Long binary numbers: BigInt keeps every digit
console.log(BigInt("0b" + "1".repeat(64)).toString()); // 18446744073709551615

Frequently asked questions

How do you convert binary to decimal?

Give each bit a place value, starting with 1 on the right and doubling to the left (1, 2, 4, 8, 16...). Add the place values of the bits that are 1. For example, 1011 = 8 + 2 + 1 = 11.

What is 11111111 in decimal?

255. It is eight 1s, so 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255, the largest number one byte can hold.

What is 1010 in decimal?

10. The 1s are on the places 8 and 2, and 8 + 2 = 10.

Can I convert very long binary numbers?

Yes. The converter uses big integers, so 64-bit and longer binary numbers convert exactly. The step-by-step working is shown for up to 32 bits.

How do I convert binary to decimal in Python?

Use int with base 2: int("101101", 2) returns 45. The code examples on this page also show how to do it by hand with a loop.

Is this converter free?

Yes. It runs in your browser, is free and needs no account.