How to Convert Binary to Decimal: 3 Methods with Examples & Code
Learn how to convert binary to decimal using three methods: positional notation, Double Dabble, and reference tables. Includes signed binary (two's complement), binary fractions, Python/JavaScript/C code, and common mistakes to avoid.
How to Convert Binary to Decimal: 3 Methods with Examples & Code
Binary-to-decimal conversion is one of the most fundamental skills in computer science and digital electronics. Whether you are debugging network packets, reading sensor outputs, or studying for a computer science exam, you need to be able to translate between the binary language that computers use and the decimal system that humans think in.
This guide teaches you three distinct methods for converting binary to decimal, from the formal positional notation approach to a mental math shortcut that lets you convert 8-bit numbers in your head in seconds. We also cover signed binary (two's complement), fractional binary, and working code in three programming languages. Try our free binary to decimal converter to follow along with any of the examples below.
Understanding the Binary Number System
Before learning the conversion methods, it helps to understand why binary exists and how it relates to decimal.
Why Computers Use Binary
Digital computers are built from billions of transistors, each of which acts as a tiny switch with two states: on and off. These two states map naturally to the two binary digits (bits): 1 and 0. While it is theoretically possible to build computers using other number bases (ternary computers have been built), binary hardware is vastly simpler, cheaper, and more reliable. Every piece of data you interact with -- text, images, video, audio -- is ultimately stored and processed as sequences of binary digits.
Positional Notation
Both binary and decimal are positional number systems, meaning the value of each digit depends on its position. In decimal, positions represent powers of 10:
- 347 = 3 × 10² + 4 × 10¹ + 7 × 10&sup0; = 300 + 40 + 7
In binary, positions represent powers of 2:
- 1011 = 1 × 2³ + 0 × 2² + 1 × 2¹ + 1 × 2&sup0; = 8 + 0 + 2 + 1 = 11
The key powers of 2 you should memorize:
| Position | Power of 2 | Decimal Value |
|---|---|---|
| 0 | 2^0 | 1 |
| 1 | 2^1 | 2 |
| 2 | 2^2 | 4 |
| 3 | 2^3 | 8 |
| 4 | 2^4 | 16 |
| 5 | 2^5 | 32 |
| 6 | 2^6 | 64 |
| 7 | 2^7 | 128 |
| 8 | 2^8 | 256 |
| 9 | 2^9 | 512 |
| 10 | 2^10 | 1,024 |
| 15 | 2^15 | 32,768 |
| 16 | 2^16 | 65,536 |
| 31 | 2^31 | 2,147,483,648 |
Method 1: Positional Notation (Power-of-2 Method)
This is the standard textbook method and the most widely taught approach to binary-to-decimal conversion.
The Algorithm
- Write down the binary number with each digit in its own column.
- Label each position with its power of 2, starting from 2^0 on the right.
- Multiply each bit by its corresponding power of 2.
- Add all the products together. The sum is the decimal value.
Example 1: Convert 1101 to Decimal
| Bit | 1 | 1 | 0 | 1 |
|---|---|---|---|---|
| Position | 3 | 2 | 1 | 0 |
| Power | 2^3=8 | 2^2=4 | 2^1=2 | 2^0=1 |
| Product | 8 | 4 | 0 | 1 |
Sum: 8 + 4 + 0 + 1 = 13
Example 2: Convert 10110110 to Decimal
| Bit | 1 | 0 | 1 | 1 | 0 | 1 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|
| Position | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Power | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
| Product | 128 | 0 | 32 | 16 | 0 | 4 | 2 | 0 |
Sum: 128 + 0 + 32 + 16 + 0 + 4 + 2 + 0 = 182
Example 3: Convert 1111111111111111 (16 bits, all ones) to Decimal
When all bits are 1, the result is 2^n - 1, where n is the number of bits:
2^16 - 1 = 65,536 - 1 = 65,535
This is the maximum value of an unsigned 16-bit integer, commonly seen in networking (port numbers range from 0 to 65,535).
When to Use This Method
Positional notation is best for:
- Formal written work and exams
- Short binary numbers (up to about 8 bits by hand)
- Understanding the mathematical foundation
- Teaching and explaining the concept to others
Method 2: Double Dabble (The Doubling Method)
The Double Dabble method is a mental arithmetic shortcut that processes the binary number from left to right. It eliminates the need to calculate or memorize large powers of 2.
The Algorithm
- Start from the leftmost (most significant) bit.
- Initialize the running total to the value of the first bit (0 or 1).
- For each subsequent bit: double the running total and add the current bit.
- After processing the last bit, the running total is the decimal value.
Example 1: Convert 11010 to Decimal
| Step | Operation | Running Total |
|---|---|---|
| 1 | Start with bit 1 | 1 |
| 2 | Double + bit 1 | 2 + 1 = 3 |
| 3 | Double + bit 0 | 6 + 0 = 6 |
| 4 | Double + bit 1 | 12 + 1 = 13 |
| 5 | Double + bit 0 | 26 + 0 = 26 |
Result: 11010 = 26
Example 2: Convert 10110011 to Decimal
| Step | Operation | Running Total |
|---|---|---|
| 1 | Start with bit 1 | 1 |
| 2 | Double + bit 0 | 2 + 0 = 2 |
| 3 | Double + bit 1 | 4 + 1 = 5 |
| 4 | Double + bit 1 | 10 + 1 = 11 |
| 5 | Double + bit 0 | 22 + 0 = 22 |
| 6 | Double + bit 0 | 44 + 0 = 44 |
| 7 | Double + bit 1 | 88 + 1 = 89 |
| 8 | Double + bit 1 | 178 + 1 = 179 |
Result: 10110011 = 179
Why It Works
Doubling the running total is mathematically equivalent to shifting all previously processed bits one position to the left (multiplying by 2). When you add the new bit, you are placing it in the ones position. This reproduces the positional notation calculation without ever explicitly computing powers of 2.
Algebraically, for binary number b3 b2 b1 b0:
- Start: b3
- Step 2: 2×b3 + b2
- Step 3: 2×(2×b3 + b2) + b1 = 4×b3 + 2×b2 + b1
- Step 4: 2×(4×b3 + 2×b2 + b1) + b0 = 8×b3 + 4×b2 + 2×b1 + b0
This is identical to the positional notation formula.
When to Use This Method
Double Dabble is best for:
- Mental arithmetic (no paper or calculator)
- Long binary numbers where tracking powers of 2 is tedious
- Quick conversions during debugging or interviews
- Situations where you process bits sequentially (like reading from a serial interface)
Method 3: Using a Reference Table
For values you encounter frequently, a reference table allows instant lookup without any calculation.
Quick Reference: Powers of 2
| Binary | Decimal |
|---|---|
| 1 | 1 |
| 10 | 2 |
| 100 | 4 |
| 1000 | 8 |
| 10000 | 16 |
| 100000 | 32 |
| 1000000 | 64 |
| 10000000 | 128 |
| 100000000 | 256 |
Common 8-Bit Values
| Binary | Decimal | Significance |
|---|---|---|
| 00000000 | 0 | Zero / null byte |
| 00000001 | 1 | Lowest bit set |
| 00001010 | 10 | Newline character (LF) |
| 00100000 | 32 | Space character in ASCII |
| 00101010 | 42 | The Answer (Hitchhiker's Guide) |
| 01000001 | 65 | Uppercase 'A' in ASCII |
| 01100001 | 97 | Lowercase 'a' in ASCII |
| 01111111 | 127 | Max signed 8-bit / DEL in ASCII |
| 10000000 | 128 | MSB set / min signed 8-bit (-128) |
| 11000000 | 192 | Network address class C |
| 11111111 | 255 | Max unsigned 8-bit / broadcast |
When to Use This Method
Table lookup is best for:
- Values you encounter repeatedly (ASCII codes, subnet masks, common constants)
- Quick reference during exams or interviews
- Building intuition about which binary patterns correspond to which decimal values
- Verifying results from the other two methods
For a complete interactive table covering all 256 byte values, visit our binary to decimal converter.
Signed Binary: Two's Complement Conversion
Unsigned binary represents only non-negative values. To represent negative numbers, modern computers universally use two's complement.
How Two's Complement Works
In an n-bit two's complement system:
- If the MSB (leftmost bit) is 0, the number is positive -- read it normally
- If the MSB is 1, the number is negative -- use the following procedure
To decode a negative two's complement number:
- Note that the number is negative (MSB = 1)
- Invert all bits (flip 0s to 1s and 1s to 0s)
- Add 1 to the result
- Convert the result to decimal and place a minus sign in front
Example: Convert 8-bit Signed Binary 11101100
- MSB is 1, so the value is negative
- Invert: 11101100 → 00010011
- Add 1: 00010011 + 1 = 00010100
- Convert 00010100 to decimal: 16 + 4 = 20
- Apply negative sign: -20
Example: Convert 8-bit Signed Binary 01010110
- MSB is 0, so the value is positive
- Convert normally: 64 + 16 + 4 + 2 = 86
Two's Complement Ranges
| Bits | Unsigned Range | Signed Range |
|---|---|---|
| 8 | 0 to 255 | -128 to 127 |
| 16 | 0 to 65,535 | -32,768 to 32,767 |
| 32 | 0 to 4,294,967,295 | -2,147,483,648 to 2,147,483,647 |
| 64 | 0 to 18.4 × 10^18 | -9.2 × 10^18 to 9.2 × 10^18 |
The advantage of two's complement is that addition and subtraction work identically for both signed and unsigned numbers at the hardware level, simplifying CPU design.
Binary Fractions: Converting the Part After the Point
Binary numbers can include a fractional part, separated by a binary point (analogous to the decimal point). Digits after the binary point represent negative powers of 2.
Fractional Position Values
| Position | Power | Decimal Value |
|---|---|---|
| -1 | 2^(-1) | 0.5 |
| -2 | 2^(-2) | 0.25 |
| -3 | 2^(-3) | 0.125 |
| -4 | 2^(-4) | 0.0625 |
| -5 | 2^(-5) | 0.03125 |
| -6 | 2^(-6) | 0.015625 |
Example: Convert 110.101 to Decimal
Integer part (110):
- 1 × 4 + 1 × 2 + 0 × 1 = 6
Fractional part (.101):
- 1 × 0.5 + 0 × 0.25 + 1 × 0.125 = 0.625
Total: 6 + 0.625 = 6.625
Example: Convert 1.001 to Decimal
- 1 × 1 = 1
- 0 × 0.5 = 0
- 0 × 0.25 = 0
- 1 × 0.125 = 0.125
Total: 1 + 0 + 0 + 0.125 = 1.125
The Precision Problem
Not all decimal fractions have exact binary representations. For example, decimal 0.1 in binary is the infinitely repeating fraction 0.0001100110011... This is why expressions like 0.1 + 0.2 do not equal exactly 0.3 in most programming languages -- the binary representation requires rounding, introducing tiny errors. This limitation is inherent to binary floating-point representation (IEEE 754), not a bug in any particular language.
Programming Examples
Python
JavaScript
C
Notice that the C implementation of binaryToDecimal uses the Double Dabble algorithm internally: decimal = decimal * 2 + (binary[i] - '0') is exactly "double the running total and add the current bit."
Common Mistakes to Avoid
Mistake 1: Reading Bit Positions from Left to Right
The rightmost bit is position 0, not the leftmost. Binary 1000 is 8 (2^3), not 1. Always count positions from right to left.
Mistake 2: Forgetting That Position 0 Equals 1, Not 0
The rightmost bit represents 2^0 = 1, not 0. Students sometimes start the power count at 1 instead of 0, making every value exactly half of the correct answer.
Mistake 3: Treating Signed Binary as Unsigned
The 8-bit binary 10000001 is 129 as unsigned but -127 as signed (two's complement). Always know whether you are working with signed or unsigned interpretation. In most programming contexts, int types are signed by default.
Mistake 4: Assuming All Decimal Fractions Have Exact Binary Representations
Decimal 0.1 cannot be represented exactly in binary -- it becomes an infinite repeating fraction (0.0001100110011...). This is why 0.1 + 0.2 !== 0.3 in JavaScript, Python, C, and virtually every other language. When precision matters, use integer arithmetic (cents instead of dollars) or dedicated decimal types.
Mistake 5: Confusing Binary and Decimal When Numbers Look Similar
Binary 1000 (= decimal 8) and decimal 1000 (one thousand) look identical but represent vastly different values. Always clarify the base, especially when communicating with others. In code, use prefixes: 0b1000 for binary, plain 1000 for decimal.
Mistake 6: Overflow When Working with Fixed Bit Widths
An 8-bit unsigned variable can hold 0-255. Adding 1 to 255 (11111111) overflows to 0 (00000000). In signed 8-bit, adding 1 to 127 (01111111) overflows to -128 (10000000). Always check whether your bit width can hold the expected range of values.
Mistake 7: Mixing Up Binary and BCD Representations
Binary and binary-coded decimal (BCD) produce different bit patterns for the same number. Decimal 42 in standard binary is 101010 (6 bits), but in BCD it is 0100 0010 (8 bits, with each decimal digit encoded separately as 4 bits). BCD is less space-efficient but preserves exact decimal digit representation, which is why it appears in some financial and display hardware.
Real-World Applications of Binary-to-Decimal Conversion
Understanding binary-to-decimal conversion is not just an academic exercise. Here are the most common places where this skill is directly useful.
Network Engineering
IP addresses like 192.168.1.0 are stored internally as 32-bit binary numbers. Subnetting requires converting between binary subnet masks and their decimal equivalents. For example, the subnet mask 255.255.255.0 is 11111111.11111111.11111111.00000000 in binary -- understanding this binary pattern is essential for calculating network and host portions of an address.
Embedded Systems and IoT
Microcontrollers and sensors often communicate using binary register values. When reading an 8-bit ADC (Analog-to-Digital Converter), you receive a binary value like 10110100 that must be converted to a decimal voltage reading (180 out of 255, mapping to a proportional voltage). Debug interfaces frequently display memory contents in binary that engineers must interpret.
Debugging and Reverse Engineering
When debugging low-level software, memory dumps, core files, and register states are displayed in binary or hexadecimal. Converting these to decimal helps understand what values are actually stored. Similarly, analyzing binary file formats, network protocols, or encrypted data requires fluency in binary-to-decimal translation.
Computer Science Education
Binary-to-decimal conversion is a gateway topic that leads to understanding CPU architecture, memory addressing, Boolean algebra, and digital logic design. Mastering this conversion builds the foundation for topics like assembly language, operating systems, and computer networks.
Frequently Asked Questions
How do you convert binary 1010 to decimal?
Binary 1010 = (1 × 8) + (0 × 4) + (1 × 2) + (0 × 1) = 8 + 0 + 2 + 0 = 10. This is a commonly used example because the binary representation 1010 conveniently converts to the round decimal number 10.
What is the fastest way to convert binary to decimal in your head?
Use the Double Dabble method: start from the leftmost bit, double the running total and add each bit as you move right. For example, 1101: start with 1, double+1=3, double+0=6, double+1=13. No need to memorize powers of 2.
What is the largest number you can represent with 8 bits?
For unsigned 8-bit: 11111111 = 255 (2^8 - 1). For signed 8-bit (two's complement): 01111111 = 127 (2^7 - 1). The signed range is -128 to 127, covering 256 total values.
How does binary relate to hexadecimal?
Each hexadecimal digit represents exactly 4 binary bits (since 16 = 2^4). So binary 11111111 = hex FF (decimal 255), and binary 10101010 = hex AA (decimal 170). Hex is widely used as a compact shorthand for binary. For hex-to-binary conversion, see our hex to binary converter.
How does binary relate to octal?
Each octal digit represents exactly 3 binary bits (since 8 = 2^3). Binary 111111111 = octal 777 (decimal 511). Octal is used in Unix file permissions (chmod). For more details, see our binary to octal converter.
Why is two's complement used instead of sign-magnitude?
Two's complement has two key advantages over sign-magnitude (where the MSB is simply a +/- flag): (1) there is only one representation of zero (in sign-magnitude, both 00000000 and 10000000 equal zero), and (2) addition and subtraction use the same hardware circuit for both positive and negative numbers, simplifying CPU design.
Can you convert very large binary numbers to decimal?
Yes, the same methods work for any length. For mental arithmetic with large numbers, the Double Dabble method scales well. In programming, Python handles arbitrary-precision integers natively, JavaScript provides BigInt, and C has libraries like GMP for arbitrary-precision arithmetic.
What is binary-coded decimal (BCD)?
BCD is a different encoding where each decimal digit is represented by 4 binary bits individually, rather than converting the entire number. For example, decimal 42 in BCD is 0100 0010 (4 = 0100, 2 = 0010), not 101010 (which is 42 in standard binary). BCD is used in some financial and display applications where exact decimal representation is required.
Summary
Binary-to-decimal conversion is built on positional notation: each bit position represents a power of 2. You can perform the conversion using three methods depending on the situation:
- Positional Notation -- The formal method. Multiply each bit by its power of 2 and sum. Best for written work and short numbers.
- Double Dabble -- The mental math shortcut. Process left to right, doubling and adding. Best for quick in-head conversions and long numbers.
- Reference Table -- Instant lookup for frequently encountered values like ASCII codes, subnet masks, and byte boundaries.
For signed binary, use two's complement: if the MSB is 1, invert all bits, add 1, and negate. For binary fractions, extend the positional notation to negative powers of 2.
Ready to practice? Use our free binary to decimal converter to convert any binary number -- unsigned, signed, or fractional -- with step-by-step breakdown and instant verification.