How to Convert Binary to Decimal
Converting binary to decimal uses positional notation, the same principle behind every number system. Each digit in a binary number represents a power of 2, just as each digit in a decimal number represents a power of 10. Because binary is base-2 and has only two symbols (0 and 1), each bit position doubles in value from right to left: 1, 2, 4, 8, 16, 32, 64, 128, and so on.
Step-by-Step Positional Notation Method
Step 1: Write down the binary number
Write out each binary digit. For example: 10110
Step 2: Assign powers of 2 to each bit position from right to left
Starting at position 0 (rightmost bit), label each bit with its power of 2:
| Bit: | 1 | 0 | 1 | 1 | 0 |
| Power: | 24 | 23 | 22 | 21 | 20 |
| Value: | 16 | 8 | 4 | 2 | 1 |
Step 3: Multiply each bit by its corresponding power of 2
- 1 × 24 = 16
- 0 × 23 = 0
- 1 × 22 = 4
- 1 × 21 = 2
- 0 × 20 = 0
Step 4: Sum all the products to get the decimal result
16 + 0 + 4 + 2 + 0 = 22
General Formula:
Decimal = b(n) × 2n + b(n-1) × 2n-1 + ... + b(1) × 21 + b(0) × 20
Where b(i) is the binary digit at position i (either 0 or 1).
The Double Dabble Method
The Double Dabble method (also known as the doubling method) is a mental arithmetic shortcut that avoids calculating large powers of 2. Instead of multiplying each bit by its power and summing, you process the binary number from left to right using a simple rule: double the running total and add the current bit.
Double Dabble Example: 11010 to Decimal
Binary input: 11010
1. Start with the leftmost bit: 1 (running total = 1)
2. Double 1 = 2, add next bit 1 = 3
3. Double 3 = 6, add next bit 0 = 6
4. Double 6 = 12, add next bit 1 = 13
5. Double 13 = 26, add next bit 0 = 26
Result: Binary 11010 = Decimal 26
Double Dabble Example: 10110011 to Decimal
Binary input: 10110011
1. Start: 1
2. Double 1 = 2, add 0 = 2
3. Double 2 = 4, add 1 = 5
4. Double 5 = 10, add 1 = 11
5. Double 11 = 22, add 0 = 22
6. Double 22 = 44, add 0 = 44
7. Double 44 = 88, add 1 = 89
8. Double 89 = 178, add 1 = 179
Result: Binary 10110011 = Decimal 179
The Double Dabble method is particularly useful for converting long binary numbers by hand, since you never need to remember large powers of 2. It works because doubling the running total is equivalent to shifting all previous bits one position left (multiplying by 2) before adding the next bit.
Binary to Decimal Conversion Examples
Convert 1010 to Decimal
Binary input: 1010
- 1 × 23 = 8
- 0 × 22 = 0
- 1 × 21 = 2
- 0 × 20 = 0
8 + 0 + 2 + 0 = 10
Convert 11111111 to Decimal
Binary input: 11111111 (8 bits, all ones)
- 1 × 128 = 128
- 1 × 64 = 64
- 1 × 32 = 32
- 1 × 16 = 16
- 1 × 8 = 8
- 1 × 4 = 4
- 1 × 2 = 2
- 1 × 1 = 1
128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255
This is the maximum unsigned value for one byte (8 bits): 28 - 1 = 255.
Convert 10000000 to Decimal
Binary input: 10000000
Only the MSB (Most Significant Bit) is set:
1 × 27 = 128
In 8-bit signed (two's complement), this same bit pattern represents -128, the most negative 8-bit value.
Convert 1100100 to Decimal
Binary input: 1100100
- 1 × 64 = 64
- 1 × 32 = 32
- 0 × 16 = 0
- 0 × 8 = 0
- 1 × 4 = 4
- 0 × 2 = 0
- 0 × 1 = 0
64 + 32 + 0 + 0 + 4 + 0 + 0 = 100
Binary to Decimal Conversion Table
This complete binary to decimal conversion table covers all 256 byte values from 0 to 255. Each row shows the decimal value, its 8-bit binary representation, hexadecimal equivalent, and octal representation.
Quick Reference (Powers of 2 & Common Values):
| Decimal | Binary | Hex | Octal |
|---|---|---|---|
| 0 | 00000000 | 00 | 0 |
| 1 | 00000001 | 01 | 1 |
| 2 | 00000010 | 02 | 2 |
| 4 | 00000100 | 04 | 4 |
| 8 | 00001000 | 08 | 10 |
| 10 | 00001010 | 0A | 12 |
| 16 | 00010000 | 10 | 20 |
| 32 | 00100000 | 20 | 40 |
| 42 | 00101010 | 2A | 52 |
| 64 | 01000000 | 40 | 100 |
| 100 | 01100100 | 64 | 144 |
| 127 | 01111111 | 7F | 177 |
| 128 | 10000000 | 80 | 200 |
| 255 | 11111111 | FF | 377 |
This table covers all possible single-byte values (0-255) with their binary, hexadecimal, and octal equivalents. For values beyond 255, apply the same positional notation method to larger binary numbers.
Signed Binary & Two's Complement
Unsigned binary can only represent non-negative numbers. To represent negative numbers, computers use two's complement, the standard signed binary system used by virtually all modern processors.
How Two's Complement Works
In two's complement, the most significant bit (MSB) is the sign bit: 0 means positive, 1 means negative. The remaining bits hold the magnitude, but negative values are encoded by inverting all bits and adding 1.
Example: Convert 8-bit signed binary 11111001 to decimal
1. MSB is 1, so the number is negative
2. Invert all bits: 11111001 → 00000110
3. Add 1: 00000110 + 1 = 00000111 = 7
4. Apply the negative sign: -7
Two's Complement Range
| Bits | Minimum | Maximum | Total Values |
|---|---|---|---|
| 8 | -128 | 127 | 256 |
| 16 | -32,768 | 32,767 | 65,536 |
| 32 | -2,147,483,648 | 2,147,483,647 | 4,294,967,296 |
Binary Fractions to Decimal
Binary numbers can have a fractional part, separated by a binary point (similar to a decimal point). Bits after the binary point represent negative powers of 2: 2-1 = 0.5, 2-2 = 0.25, 2-3 = 0.125, and so on.
Example: Convert 101.11 to Decimal
Binary input: 101.11
Integer part (101):
- 1 × 22 = 4
- 0 × 21 = 0
- 1 × 20 = 1
Fractional part (.11):
- 1 × 2-1 = 0.5
- 1 × 2-2 = 0.25
4 + 0 + 1 + 0.5 + 0.25 = 5.75
Example: Convert 1.0101 to Decimal
Binary input: 1.0101
- 1 × 20 = 1
- 0 × 2-1 = 0
- 1 × 2-2 = 0.25
- 0 × 2-3 = 0
- 1 × 2-4 = 0.0625
1 + 0 + 0.25 + 0 + 0.0625 = 1.3125
Note: Some decimal fractions cannot be represented exactly in binary (for example, 0.1 in decimal is a repeating fraction in binary: 0.0001100110011...). This is why floating-point arithmetic can produce small rounding errors in programming.
Binary to Decimal in Programming
Most programming languages provide built-in functions for converting binary strings to decimal integers. Here are examples in the three most commonly used languages.
Python
# Convert binary string to decimal
binary_str = "10110011"
decimal_value = int(binary_str, 2)
print(decimal_value) # 179
# Binary literal in Python
x = 0b10110011
print(x) # 179
# Convert decimal back to binary
print(bin(179)) # '0b10110011'
# Two's complement for signed 8-bit
def signed_binary_to_decimal(binary_str, bits=8):
value = int(binary_str, 2)
if value >= 2**(bits - 1):
value -= 2**bits
return value
print(signed_binary_to_decimal("11111001")) # -7
print(signed_binary_to_decimal("01111111")) # 127JavaScript
// Convert binary string to decimal
const binaryStr = "10110011";
const decimal = parseInt(binaryStr, 2);
console.log(decimal); // 179
// Binary literal in JavaScript
const x = 0b10110011;
console.log(x); // 179
// Convert decimal back to binary
console.log((179).toString(2)); // '10110011'
// For large binary values, use BigInt
const bigBin = "1111111111111111111111111111111111111111";
const bigDec = BigInt("0b" + bigBin);
console.log(bigDec.toString()); // '1099511627775'C
#include <stdio.h>
#include <string.h>
#include <math.h>
long binaryToDecimal(const char *binary) {
long decimal = 0;
int len = strlen(binary);
for (int i = 0; i < len; i++) {
if (binary[i] == '1') {
decimal += (long)pow(2, len - 1 - i);
}
}
return decimal;
}
int main() {
printf("%ld\n", binaryToDecimal("10110011")); // 179
printf("%ld\n", binaryToDecimal("11111111")); // 255
printf("%ld\n", binaryToDecimal("1100100")); // 100
// C also supports binary literals (C23/GCC extension)
// int x = 0b10110011; // 179
return 0;
}Applications
- Computer architecture: Understanding how CPUs process data at the binary level and convert to human-readable decimal output
- Networking: IP address and subnet mask calculations require binary-to-decimal conversion (e.g., subnet mask 11111111.11111111.11111111.00000000 = 255.255.255.0)
- Digital electronics: Reading sensor outputs, ADC (Analog-to-Digital Converter) values, and logic gate states
- Programming: Bitwise operations, bit flags, permissions, and debugging binary data
- Data encoding: Understanding character encodings like ASCII (7-bit) and UTF-8 (variable-length binary sequences)
- Cryptography: Binary operations underpin XOR encryption, hash functions, and block ciphers used in our Vernam cipher and other tools