How to Convert Decimal Numbers to Binary Numbers

Binary and decimal are two ways of expressing the same numerical values — one that computers speak natively, and one that humans use every day. Understanding how to move between them is a foundational skill in computing, programming, and digital electronics. Whether you're studying computer science, debugging low-level code, or just curious about how machines process numbers, the conversion process follows a consistent, learnable logic.

What Are Decimal and Binary Number Systems?

Decimal is the base-10 number system. It uses ten digits — 0 through 9 — and each position in a number represents a power of 10. The number 347, for example, means (3 × 100) + (4 × 10) + (7 × 1).

Binary is the base-2 number system. It uses only two digits — 0 and 1 — and each position represents a power of 2. These two states map directly to the on/off switching behavior of transistors inside processors and memory chips. Every piece of data your computer stores or processes ultimately reduces to binary.

The Core Method: Repeated Division by 2

The most widely taught and reliable method for converting a decimal integer to binary is repeated division by 2, sometimes called the division-remainder method.

How it works:

  1. Divide your decimal number by 2
  2. Record the remainder (either 0 or 1)
  3. Divide the quotient by 2 again
  4. Repeat until the quotient reaches 0
  5. Read the remainders bottom to top — that sequence is your binary number

Example — converting 45 to binary:

StepDividendDivided by 2QuotientRemainder
145÷ 2221
222÷ 2110
311÷ 251
45÷ 221
52÷ 210
61÷ 201

Reading remainders from bottom to top: 101101

So 45 in decimal = 101101 in binary.

Verification: 1×32 + 0×16 + 1×8 + 1×4 + 0×2 + 1×1 = 32 + 8 + 4 + 1 = 45

An Alternative: The Subtraction (Powers of 2) Method

Some people find it more intuitive to work with powers of 2 directly rather than dividing repeatedly.

How it works:

  1. List the powers of 2 in descending order that are less than or equal to your number: 128, 64, 32, 16, 8, 4, 2, 1
  2. Starting with the largest, ask: does this power of 2 fit into the remaining value?
  3. If yes, write 1 and subtract it from your number
  4. If no, write 0 and move to the next power

Example — converting 45 to binary using this method:

  • 64 > 45 → 0
  • 32 ≤ 45 → 1 (45 − 32 = 13 remaining)
  • 16 > 13 → 0
  • 8 ≤ 13 → 1 (13 − 8 = 5 remaining)
  • 4 ≤ 5 → 1 (5 − 4 = 1 remaining)
  • 2 > 1 → 0
  • 1 ≤ 1 → 1 (1 − 1 = 0 remaining)

Result: 0101101 → strip the leading zero → 101101

Both methods produce identical results. The division method scales more mechanically for large numbers; the subtraction method can be faster mentally for smaller ones.

Converting Decimal Fractions to Binary 🔢

Whole numbers are straightforward, but decimal fractions (numbers with a fractional part, like 0.625) follow a different process.

How it works — multiply by 2 repeatedly:

  1. Multiply the fractional part by 2
  2. Record the integer part of the result (either 0 or 1)
  3. Keep the new fractional part and multiply again
  4. Repeat until the fraction reaches 0 or you've reached sufficient precision
  5. Read the integer parts top to bottom

Example — converting 0.625 to binary:

StepValue× 2Integer PartRemaining Fraction
10.6251.2510.25
20.250.500.5
30.51.010.0 (stop)

Result: 0.101 in binary

Not all decimal fractions convert to finite binary representations. The fraction 0.1 in decimal, for instance, produces an infinitely repeating binary sequence — a key reason floating-point arithmetic in software can introduce small rounding errors.

Variables That Affect How You Apply This in Practice

The math itself is fixed, but how you work with binary conversions in real scenarios depends on several factors:

  • Bit-width constraints — in computing, numbers are stored in fixed-width registers (8-bit, 16-bit, 32-bit, 64-bit). A result may need to be zero-padded to fill the required width. The number 5 in binary is 101, but in an 8-bit context it's stored as 00000101.
  • Signed vs. unsigned representation — negative numbers in binary require special encoding conventions such as two's complement, which changes how the most significant bit is interpreted.
  • Programming language context — languages like Python, JavaScript, C, and Java each have built-in functions for decimal-to-binary conversion (bin() in Python, toString(2) in JavaScript), but understanding what those functions return — and their edge cases with negative numbers or large integers — depends on the language's data type model.
  • Manual vs. tool-assisted conversion — for learning or exam contexts, working through the division or subtraction method by hand builds genuine understanding. For production code or bulk data work, built-in functions or lookup tables are more appropriate.

Why Binary Literacy Still Matters

Even though modern programming rarely requires manual binary conversion, understanding it underpins related concepts: bitwise operations, hexadecimal shorthand (hex groups four binary digits at a time), network subnet masks, file permissions in Unix/Linux, and color values in design tools (RGB values expressed in hex are directly tied to binary representation).

The conversion process is deterministic and exact for integers. For fractions, precision limits come into play quickly — and those limits have real consequences in software behavior.

Where this becomes specific to your situation is in how much depth you need: whether you're working within a particular bit-width constraint, handling signed arithmetic, writing code in a specific language, or simply building conceptual fluency before moving deeper into computer architecture or data representation. The method is the same; the context around it shapes what you do with the result.