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.
Full converter (all five bases) → · How to convert binary to decimal →
Step by step
- Divide by 2. Divide the decimal number by 2. Write down the quotient and the remainder (0 or 1).
- Repeat with the quotient. Divide that quotient by 2 again. Keep going until the quotient is 0.
- Read the remainders bottom to top. The last remainder is the leftmost binary digit. Reading bottom to top gives the binary number.
- Check. Type the decimal number in the converter above and compare.
Worked example: 42₁₀ → 101010₂
| Division | Quotient | Remainder |
|---|---|---|
| 42 ÷ 2 | 21 | 0 |
| 21 ÷ 2 | 10 | 1 |
| 10 ÷ 2 | 5 | 0 |
| 5 ÷ 2 | 2 | 1 |
| 2 ÷ 2 | 1 | 0 |
| 1 ÷ 2 | 0 | 1 |
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₂ |
|---|---|---|---|
| 0 | 0 | 8 | 1000 |
| 1 | 1 | 9 | 1001 |
| 2 | 10 | 10 | 1010 |
| 3 | 11 | 11 | 1011 |
| 4 | 100 | 12 | 1100 |
| 5 | 101 | 13 | 1101 |
| 6 | 110 | 14 | 1110 |
| 7 | 111 | 15 | 1111 |
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.