Skip to content
AgileLogics

Decimal to Binary

Converts a base-10 (decimal) number into its base-2 (binary) equivalent.

How it works

Enter a whole number (e.g. 10) and click Convert.

How do you convert decimal to binary?

The standard method is repeated division by 2. Divide the number by 2, note the remainder, then divide the quotient again, and stop when the quotient is 0. The remainders, read from bottom to top, are the binary digits. For example, 156 gives remainders 0, 0, 1, 1, 1, 0, 0, 1, which read upward spell 10011100.

Each division strips off the lowest bit: an even number ends in 0, an odd one in 1. That's why the first remainder you write is the rightmost digit of the answer, and why you read the column backwards.

How to use the tool

  1. Type a non-negative whole number such as 156.
  2. Press Convert.
  3. Copy the binary result: 10011100.

Digits only. No commas, spaces inside the number, signs, decimal points or scientific notation. Leading and trailing spaces are trimmed, and 0 converts to 0.

Worked example: 156 by repeated division

Step Division Quotient Remainder
1 156 ÷ 2 78 0
2 78 ÷ 2 39 0
3 39 ÷ 2 19 1
4 19 ÷ 2 9 1
5 9 ÷ 2 4 1
6 4 ÷ 2 2 0
7 2 ÷ 2 1 0
8 1 ÷ 2 0 1

Reading the remainder column from step 8 up to step 1 gives 10011100. Check it the other way: 128 + 16 + 8 + 4 = 156.

A faster way for small numbers

If you know your powers of two, subtraction is quicker than division. Take the largest power of two that fits, subtract it, and repeat with what's left:

  • 156 - 128 = 28, so bit 128 is on
  • 28 - 16 = 12, so bit 16 is on
  • 12 - 8 = 4, so bit 8 is on
  • 4 - 4 = 0, so bit 4 is on

Bits 64, 32, 2 and 1 stay off. Writing 1 for each power used and 0 for each skipped, from 128 down to 1, gives the same 10011100.

Numbers worth recognising

Decimal Binary Why it matters
192 11000000 First octet of private 192.168.x.x addresses
255 11111111 Largest value in one byte
1024 10000000000 A power of two is always a 1 followed by zeros
65535 1111111111111111 Largest unsigned 16-bit value, the top TCP/UDP port
4294967295 32 ones Largest unsigned 32-bit value

Spotting those shapes saves time when you're reading masks, flags and limits in code.

Negative numbers and fractions

This converter handles non-negative integers only, and it's honest about it: -5 and 3.5 both produce an error rather than a guess. Computers store negative integers as two's complement, which depends on the bit width you choose, so there's no single right answer for "-5 in binary" until you say 8, 16 or 32 bits. The FAQ above shows the three-step manual method.

Fractions are a different problem. 0.5 is 0.1 in binary, but 0.1 decimal repeats forever in base 2, which is why floating-point arithmetic has rounding error. To see exactly how a computer stores a fraction, use the IEEE-754 analyzer.

In code

Most languages have this built in. Python's bin() returns '0b10011100' for 156, and JavaScript's toString(2) returns '10011100'. This tool uses the JavaScript method and rejects anything above Number.MAX_SAFE_INTEGER so that very large inputs can't be silently rounded before conversion.

See also

  • Binary to decimal reverses the conversion so you can check your work.
  • Decimal to hex gives a shorter form of the same value, four bits per digit.
  • Text to binary converts characters rather than numbers, one 8-bit byte at a time.

Last updated

Frequently asked questions

How do you convert decimal to binary using division?
Divide the number by 2 and write down the remainder (0 or 1). Keep dividing the quotient by 2 until it reaches 0, then read the remainders from the last one to the first. For 156 the remainders, read upward, spell 10011100.
Can it convert negative numbers?
No. A minus sign triggers the "Enter a valid decimal number" error. To get the two's complement form of a negative number, convert the positive value, pad it to your bit width, flip every bit and add 1. For -5 in 8 bits that's 00000101, then 11111010, then 11111011.
Can it convert decimals like 3.5 or 0.1?
No, only whole numbers. A decimal point, comma, exponent like 1e3, or any non-digit character is rejected. Fractions in binary need a separate multiply-by-2 method, and many, like 0.1, never terminate.
Why isn't the output padded to 8 bits?
The tool prints the shortest binary form, so 5 gives 101. If you need a full byte, add zeros on the left until there are 8 digits: 00000101.
What is the largest number I can convert?
9007199254740991 (2^53 - 1), which becomes fifty-three 1s. One more, 9007199254740992, shows "That number is too large to convert precisely."