NumForge LogoNumForge
Explore
Radix Conversion6 min read

How to convert a decimal to binary?

A foundational tutorial on the successive division-by-2 method, powers-of-two subtraction, and fractional binary precision.

Overview

Translating base-10 decimal numbers into base-2 binary strings is the core gateway between human mathematics and silicon hardware logic. Learn the mechanics of repeated division and positional weighting.

1. Understanding the Core Concept

Decimal (Base 10) uses ten digits (0–9) where each position represents an increasing power of 10 (1, 10, 100, 1000). Binary (Base 2) uses only two discrete binary digits or bits: 0 and 1. In digital computing, binary is the physical language of microprocessors because transistors act as bi-stable electrical switches: a transistor is either OFF (0 volts, logic 0) or ON (supply voltage, logic 1). Converting decimal to binary allows high-level numerical algorithms to run directly on physical semiconductor gates.

2. How Does It Work? Step-by-Step Methodology

The standard algorithm is the successive division by 2 method. Take the decimal integer, divide by 2, and write down the integer quotient alongside the remainder (which will always be either 0 or 1). Continue dividing each resulting quotient by 2 until the quotient becomes 0. The binary equivalent is formed by reading the sequence of remainders in reverse order—starting with the last remainder computed (the Most Significant Bit, or MSB) and ending with the first remainder (the Least Significant Bit, or LSB). An alternative visual approach is the Powers-of-Two Subtraction method, where you identify the highest power of 2 less than or equal to the number, subtract it, place a 1, and repeat for all decreasing powers of two.

Mathematical AlgorithmFormal Method
Successive Division Algorithm: Q_0 = Decimal Integer Q_1 = ⌊Q_0 ÷ 2⌋, R_0 = Q_0 mod 2 (LSB) Q_2 = ⌊Q_1 ÷ 2⌋, R_1 = Q_1 mod 2 ... Q_n = 0, R_{n-1} = Q_{n-1} mod 2 (MSB) Binary Result = (R_{n-1} R_{n-2} ... R_1 R_0)_2 Positional Check Formula: Decimal Value = Σ (b_i × 2^i) for i = 0 to n-1
Worked Problem

3. Detailed Worked Example & Verification

Example Problem: Convert decimal 156 into binary. Step 1: 156 ÷ 2 = 78, remainder 0 (LSB) Step 2: 78 ÷ 2 = 39, remainder 0 Step 3: 39 ÷ 2 = 19, remainder 1 Step 4: 19 ÷ 2 = 9, remainder 1 Step 5: 9 ÷ 2 = 4, remainder 1 Step 6: 4 ÷ 2 = 2, remainder 0 Step 7: 2 ÷ 2 = 1, remainder 0 Step 8: 1 ÷ 2 = 0, remainder 1 (MSB) Quotient is 0. Reading remainders from bottom to top: Result: 156_10 = 10011100_2. Verification via Powers of Two: 156 = 128 + 16 + 8 + 4 = (1 × 2⁷) + (0 × 2⁶) + (0 × 2⁵) + (1 × 2⁴) + (1 × 2³) + (1 × 2²) + (0 × 2¹) + (0 × 2⁰) = 10011100_2 (Confirmed).

4. Essential Rules & Edge Cases

  • Binary remainders can ONLY be 0 or 1. Any other remainder indicates an arithmetic error.
  • The last remainder calculated is the Most Significant Bit (MSB); the first remainder is the Least Significant Bit (LSB).
  • For decimal fractions (e.g. 0.625), multiply by 2 repeatedly and read the integer parts from top to bottom (0.625 × 2 = 1.25 -> 1; 0.25 × 2 = 0.5 -> 0; 0.5 × 2 = 1.0 -> 1 => 0.101_2).
  • Leading zeros do not change the mathematical value of an unsigned binary number (00101_2 = 101_2 = 5_10), but fixed-width registers require zero-padding.
  • Zero in decimal is always 0 in binary.

5. Practical Engineering Applications

  • Microprocessor Arithmetic Logic Units (ALUs): Adding and multiplying binary numbers in silicon.
  • Networking Subnetting: Converting dotted-decimal IPv4 netmasks into 32-bit binary prefix masks.
  • Firmware Bitmasking: Setting, clearing, and toggling hardware configuration registers.
  • Data Compression: Huffman encoding and variable-length bitstream serialization.

6. Common Mistakes to Avoid

  • WarningReading remainders from top to bottom instead of bottom to top (writing 00111001 instead of 10011100).
  • WarningStopping division before the quotient reaches zero.
  • WarningConfusing decimal fractional division with integer division.
Interactive Verification

Try It in Your Browser (0ms Latency)

Validate these formulas instantly with NumForge's deterministic hardware-grade online tools.

FAQ

Frequently Asked Questions

Why do computers only understand binary?

Electronic circuits are built with millions of transistors operating as simple on/off switches. Two stable voltage states (high vs. low) provide maximum noise immunity and physical reliability.

Can all decimal fractions be converted to exact binary fractions?

No. Just as 1/3 produces a repeating decimal (0.333...), fractions like 0.1 produce an infinite repeating binary sequence (0.0001100110011...). This is the fundamental reason behind floating-point rounding errors in software.

What is the fastest mental way to convert small decimal numbers to binary?

Memorize powers of 2 (1, 2, 4, 8, 16, 32, 64, 128). Subtract the largest power of 2 that fits into your number, place a 1 in that bit position, and repeat with the remainder.

More Learning Guides

View All 7 Guides →