Decimal to Binary Converter
Convert decimal numbers to binary (base 2) instantly. Visual bit grouping for easy reading.
How to Convert Decimal to Binary
Repeatedly divide by 2 and record the remainders:
- Divide the decimal number by 2
- Record the remainder (0 or 1)
- Divide the quotient by 2 again
- Repeat until the quotient is 0
- Read the remainders in reverse order
Example: Convert 13 to binary:
- 13 ÷ 2 = 6 remainder 1
- 6 ÷ 2 = 3 remainder 0
- 3 ÷ 2 = 1 remainder 1
- 1 ÷ 2 = 0 remainder 1
- Result: 1101 (reading remainders in reverse)
Code Examples
const decimal = 10;
const binary = decimal.toString(2); // "1010"
const padded = decimal.toString(2).padStart(8, '0'); // "00001010"Frequently Asked Questions
How do I convert decimal to binary?
Divide the decimal number by 2 repeatedly, noting the remainders. Read the remainders in reverse order. For example, 10 ÷ 2 = 5r0, 5 ÷ 2 = 2r1, 2 ÷ 2 = 1r0, 1 ÷ 2 = 0r1, giving 1010.
How many bits do I need for a number?
The number of bits needed is ⌈log₂(n+1)⌉. Common sizes: 8 bits (0-255), 16 bits (0-65535), 32 bits (0-4.29B). Negative numbers require an extra sign bit.
What's the 0b prefix?
The 0b prefix indicates a binary number in languages like JavaScript, Python, and Rust. For example, 0b1010 equals decimal 10. It helps distinguish binary from decimal literals.
Related Tools
Binary to Decimal Converter
Convert binary numbers to decimal (base 10) instantly.
Binary Calculator
Add, subtract, multiply, and divide binary numbers with decimal and hex output.
Decimal to Hexadecimal Converter
Convert decimal numbers to hexadecimal (base 16) instantly.
Universal Number Base Converter
Convert numbers between any bases from 2 to 36.