radixflip

How to Convert Decimal to Binary

Divide by 2, write down the remainder, repeat with the quotient until it hits 0, then read the remainders bottom to top. Try it live below — type a decimal number and the binary answer appears instantly.

Decimal to Binary Converter

Type in either box. Both stay in sync.

42₁₀ = 101010₂. ASCII: '*'.

Full converter (all five bases) →  ·  How to convert binary to decimal →

Step by step

  1. Divide by 2. Divide the decimal number by 2. Write down the quotient and the remainder (0 or 1).
  2. Repeat with the quotient. Divide that quotient by 2 again. Keep going until the quotient is 0.
  3. Read the remainders bottom to top. The last remainder is the leftmost binary digit. Reading bottom to top gives the binary number.
  4. Check. Type the decimal number in the converter above and compare.
Remainder42 ÷ 2 = 2121 ÷ 2 = 1010 ÷ 2 = 55 ÷ 2 = 22 ÷ 2 = 11 ÷ 2 = 0010101101010₂(Read bottom to top)
Watch it: divide by 2, keep each remainder, then read the remainders bottom to top — 42₁₀ becomes 101010₂.

Worked example: 42₁₀ → 101010₂

DivisionQuotientRemainder
42 ÷ 2210
21 ÷ 2101
10 ÷ 250
5 ÷ 221
2 ÷ 210
1 ÷ 201

Remainders bottom to top: 1 0 1 0 1 0. So 42 in binary is 101010₂. Check by place value: 32 + 8 + 2 = 42.

Decimal to binary table (0–15)

Decimal₁₀Binary₂Decimal₁₀Binary₂
0081000
1191001
210101010
311111011
4100121100
5101131101
6110141110
7111151111

How to convert decimal to binary in code

Python

def decimal_to_binary(n):
    if n == 0:
        return "0"
    bits = ""
    while n > 0:
        bits = str(n % 2) + bits
        n //= 2
    return bits

print(decimal_to_binary(42))  # 101010
# Shortcut: bin(42)[2:]  → "101010"

Java

// Shortcut
String binary = Integer.toBinaryString(42); // "101010"

// Manual loop
String decimalToBinary(int n) {
    if (n == 0) return "0";
    String bits = "";
    while (n > 0) {
        bits = (n % 2) + bits;
        n /= 2;
    }
    return bits;
}

C

#include <stdio.h>

void decimalToBinary(int n) {
    if (n == 0) { printf("0"); return; }
    int bits[64], i = 0;
    while (n > 0) {
        bits[i++] = n % 2;
        n /= 2;
    }
    for (int j = i - 1; j >= 0; j--) printf("%d", bits[j]);
}

int main(void) {
    decimalToBinary(42); // prints 101010
    return 0;
}

These snippets handle positive integers. For 0, return "0" directly. RadixFlip also handles negative integers: -10 in decimal is -1010 in binary.

Frequently asked questions

How do I convert decimal to binary step by step?

Divide by 2, write down the remainder, repeat with the quotient until the quotient is 0, then read the remainders bottom to top. Example: 42 ÷ 2 = 21 remainder 0, 21 ÷ 2 = 10 remainder 1, 10 ÷ 2 = 5 remainder 0, 5 ÷ 2 = 2 remainder 1, 2 ÷ 2 = 1 remainder 0, 1 ÷ 2 = 0 remainder 1 — reading bottom to top gives 101010.

How do I convert decimal to binary by hand?

Use the divide-by-2 method on paper: keep a two-column list of quotients and remainders. Stop when the quotient reaches 0. The binary answer is the remainder column read from bottom to top. For small numbers you can also subtract powers of 2: 42 = 32 + 8 + 2, so bits 32, 8, and 2 are 1 and the rest are 0, giving 101010.

How do I convert decimal to binary in Python?

Use bin(n)[2:] for a quick conversion, for example bin(42)[2:] gives "101010". To do it by hand with a loop, repeatedly take n % 2, prepend the remainder, then set n = n // 2 until n is 0.

How do I convert decimal to binary in Java?

Use Integer.toBinaryString(n), for example Integer.toBinaryString(42) returns "101010". For a manual version, loop while n > 0, prepend (n % 2), then set n = n / 2.

How do I convert decimal to binary in C?

Loop while n > 0, store n % 2 in an array, then set n = n / 2. When the loop ends, print the array in reverse. Handle 0 as a special case: 0 in decimal is 0 in binary.

What is 42 in binary?

42 in binary is 101010. Check: 32 + 8 + 2 = 42, and those are the 1-bits in 101010.

Next: how to convert binary to decimal →