Skip to content

Binary to Decimal and Back: Understanding Number Systems

Learn how to convert numbers between binary (base-2) and decimal (base-10) systems, the foundation of digital computing.

Computing···4 min read

Introduction: Why Binary?

At the heart of every computer, smartphone, and digital device lies the binary system. While we humans typically use the decimal (base-10) system with digits 0 through 9, computers operate using binary (base-2), which only uses two digits: 0 and 1. These represent the two fundamental states of electronic circuits: off (0) and on (1). Understanding how to convert between these systems is crucial for anyone interested in computer science, programming, or digital electronics.

Decimal (Base-10) Recap

Let's quickly recap our familiar decimal system. Each position in a decimal number represents a power of 10. For example, the number 345 means:

34510=(3×102)+(4×101)+(5×100)345_{10} = (3 \times 10^2) + (4 \times 10^1) + (5 \times 10^0)
345 is 3 hundreds, 4 tens and 5 onesEach digit times its place value, a power of 10
Worked example by Binary Decimal
Show the numbers
DigitPlace valueWorth
3102 = 100300
4101 = 1040
5100 = 15

The subscript 10 denotes that it's a base-10 number.

Binary (Base-2) Explained

The binary system works similarly, but each position represents a power of 2. The digits can only be 0 or 1.

Consider the binary number 110121101_2. The subscript 2 indicates base-2. To convert this to decimal, we multiply each digit by the corresponding power of 2, starting from the rightmost digit (which corresponds to 202^0):

11012=(1×23)+(1×22)+(0×21)+(1×20)1101_2 = (1 \times 2^3) + (1 \times 2^2) + (0 \times 2^1) + (1 \times 2^0)
1101 in binary is 13Each bit times its place value, a power of 2, then add them up
Worked example; the Base Converter shows the same working
Show the numbers
DigitPlace valueWorth
123 = 88
122 = 44
021 = 20
120 = 11

So, the binary number 1101 is equivalent to the decimal number 13.

Example 2: Convert 10110210110_2 to decimal.

101102=(1×24)+(0×23)+(1×22)+(1×21)+(0×20)10110_2 = (1 \times 2^4) + (0 \times 2^3) + (1 \times 2^2) + (1 \times 2^1) + (0 \times 2^0) 101102=(1×16)+(0×8)+(1×4)+(1×2)+(0×1)10110_2 = (1 \times 16) + (0 \times 8) + (1 \times 4) + (1 \times 2) + (0 \times 1) 101102=16+0+4+2+0=221010110_2 = 16 + 0 + 4 + 2 + 0 = 22_{10}

Converting Decimal to Binary

Converting from decimal to binary involves repeatedly dividing the decimal number by 2 and recording the remainders. The binary representation is formed by reading the remainders in reverse order.

Let's convert the decimal number 131013_{10} back to binary:

Divide by 2, keep the remainder, read upward13 back to binary, one division per line
  1. 13 ÷ 2 = 61
  2. 6 ÷ 2 = 30
  3. 3 ÷ 2 = 11
  4. 1 ÷ 2 = 01

13 in binary1101

Worked example; the Base Converter shows the same working
Show the numbers
StepRemainder
13 ÷ 2 = 61
6 ÷ 2 = 30
3 ÷ 2 = 11
1 ÷ 2 = 01
13 in binary1101

Stop when the quotient reaches 0. Now, read the remainders from bottom to top: 1101. So, 1310=1101213_{10} = 1101_2, which matches our previous conversion!

Example 2: Convert 221022_{10} to binary.

  1. 22÷2=1122 \div 2 = 11 remainder 0
  2. 11÷2=511 \div 2 = 5 remainder 1
  3. 5÷2=25 \div 2 = 2 remainder 1
  4. 2÷2=12 \div 2 = 1 remainder 0
  5. 1÷2=01 \div 2 = 0 remainder 1

Reading the remainders from bottom to top: 10110. So, 2210=10110222_{10} = 10110_2.

Try it: tap a bit to flip it11012 = 1310
27128
2664
2532
2416
238
224
212
201

8 + 4 + 1 = 13

Open the full Base Converter

Binary in Code

Most programming languages provide ways to work with binary numbers or perform conversions.

Python Example:

# Convert decimal to binary string
decimal_num = 22
binary_string = bin(decimal_num)
print(f"Decimal {decimal_num} is Binary: {binary_string}") # Output: Decimal 22 is Binary: 0b10110

# The '0b' prefix indicates a binary literal

# Convert binary string to decimal integer
binary_num_string = "1101"
decimal_equivalent = int(binary_num_string, 2) # The 2 indicates base-2
print(f"Binary {binary_num_string} is Decimal: {decimal_equivalent}") # Output: Binary 1101 is Decimal: 13

# You can also write binary literals directly
binary_literal = 0b10110
print(f"Binary literal 0b10110 is Decimal: {binary_literal}") # Output: Binary literal 0b10110 is Decimal: 22

Conclusion

Understanding binary-decimal conversion is fundamental to comprehending how computers store and process information. While it might seem abstract at first, the process is systematic, relying on the concept of place value based on powers of 2. Whether you're debugging code, studying computer architecture, or just curious about the digital world, mastering these conversions is a valuable skill.

To check your own conversions, our decimal to binary converter writes out the same ladder for any number (here, 22) and lays the answer out as tiles you can tap to flip a bit:

The Decimal to Binary Converter with 22 entered. The answer reads 1 0110. Its worked example divides by 2 five times, 22, 11, 5, 2 and 1, with remainders 0, 1, 1, 0 and 1 read from the bottom up. On the right the bits are tiles under their place values, with 16 + 4 + 2 = 22 below, and the same number in octal (0o26) and hex (0x16).

computer scienceprogrammingnumber systemsbinarydecimal

Share this post