Skip to content
Aarrange

Decimal to Binary

Paste decimal numbers, one per line or split by commas. Get binary, the steps, and negatives in two's complement. Nothing leaves your browser.

Also: All bases, Hex to Dec, Dec to Hex, Bin to Dec, Hex to Bin, Bin to Hex

0
Numbers
0
Max bits
0
Errors
Input
Tab types a tab. Press Escape, then Tab, to leave the editor.
Result
The result shows here as you type.Try , or .
On this page

About Decimal to Binary

Updated

Decimal to Binary turns ordinary numbers into binary. Paste one number for homework, or a whole list, like the four parts of a subnet mask or the codes of a word. Each line is converted, and Steps shows the divisions for any of them.

Turn on Groups for bits in fours, 1111 0000, and Prefix for 0b. Set Signed to write negative numbers in 8, 16, 32 or 64 bits.

The same tool, set up for other bases: Hex to Decimal, Decimal to Hex, Binary to Decimal, Hex to Binary, Binary to Hex, Number Base Converter.

How to use it

  1. Paste decimal numbers, one per line, or load a file. Commas, tabs and semicolons also split a line, so a column from a spreadsheet works.
  2. Check From and To, next to Convert. On a phone they are under More.
  3. Press Convert (Alt C). Results shows every number in the To base and in decimal, hex, binary and octal. Output shows only the answers, line for line, for Copy and Download.
  4. Open Steps to see the math for one number, the way you would do it on paper.
  5. Swap (Alt S) puts the answers in the editor and turns From and To around, so you can check the way back.
  6. In Options: Signed for two's complement, Groups for 1111 0000 or 4,294,967,295, Prefix for 0x, 0b or 0o, and how many digits a fraction gets.

How to convert decimal to binary by hand

Divide by 2 and keep each remainder. When the answer is 0, read the remainders from the bottom up:

Decimal to binary
25 ÷ 2 = 12   remainder 1
12 ÷ 2 =  6   remainder 0
 6 ÷ 2 =  3   remainder 0
 3 ÷ 2 =  1   remainder 1
 1 ÷ 2 =  0   remainder 1

Read from the bottom up: 11001

A second way: find the largest power of 2 that fits (16 for 25), write a 1, take it off (9 left), and go down the powers: 8 fits (1, 1 left), 4 no (0), 2 no (0), 1 yes (1). Again 11001.

For a fraction, multiply by 2 instead. The whole part of each answer is the next bit after the point:

0.375 to binary
0.375 × 2 = 0.75   → 0
0.75  × 2 = 1.5    → 1
0.5   × 2 = 1.0    → 1

0.375 = 0.011

Decimal to binary chart

Decimal to binary
Dec  Binary     Dec  Binary        Dec  Binary
  0  0            8  1000          32  100000
  1  1            9  1001          64  1000000
  2  10          10  1010         100  1100100
  3  11          11  1011         127  1111111
  4  100         12  1100         128  10000000
  5  101         13  1101         255  11111111
  6  110         14  1110         256  100000000
  7  111         15  1111       1,024  10000000000

Negative numbers and two's complement

Set Signed to write a negative number in a fixed width. At 8-bit, -1 is 11111111 and -128 is 10000000.

How two's complement works, with a table and the method by hand.

Exact for big numbers

This tool uses BigInt, so 9007199254740993 (2^53 + 1) ends in 01 in binary, as it must for an odd number. A converter built on JavaScript numbers rounds it to 2^53 and gives a 1 with 53 zeros.

Why other converters round past 2^53.

Common errors

Scientific notation

A spreadsheet or a log can write one million as 1e6. The tool reads only plain digits, so it tells you what to do.

Invalid
1e6
Scientific notation is not read. Write 1e6 in full, with all its digits.
Fixed
1000000

A hex letter in a decimal number

Decimal has no letters. A number such as 1A is hex, so open Hex to Binary for it, or set From to Hex.

Invalid
1A
A is not a decimal digit. Decimal uses 0 to 9. Remove the A,
or set From to base 11 or more.

The letter O for a zero

Typed by hand, a capital O and a zero look the same. The tool names the letter, so you know what to type.

Invalid
12O4
The letter O is not a digit. Type the digit 0 (zero) in its place.
Fixed
1204

Two numbers on one line

A space can group the digits of a big number, as in 4 294 967 295. When the groups are not all 3 digits, the tool still reads one number, 10100000010001 in binary here, but marks the line, because it may be a list.

Warning
10 25 7
Read as one number, 10257. If these are separate numbers, put each on
its own line or split them with commas.
Fixed
10, 25, 7

A number too big for its bits

With Signed set to a width, every number must fit in it. The message gives the range.

Invalid
300 (Signed: 8-bit)
300 does not fit in signed 8 bits. Signed 8-bit numbers go from -128 to 127.
Pick a wider Signed setting, or set it to Off.

Decimal to binary in code and Excel

Decimal to binary
JavaScript  (25).toString(2)            // "11001"
            (-5 & 0xff).toString(2)     // "11111011", 8-bit
Python      bin(25)                     # '0b11001'
            format(25, "08b")           # '00011001'
C           printf("%b", 25)            // 11001, C23 only
Java        Integer.toBinaryString(25)  // "11001"
Excel       =DEC2BIN(25)                → 11001
            =DEC2BIN(25, 8)             → 00011001

DEC2BIN works only from -512 to 511, and a negative number comes back as 10 bits: =DEC2BIN(-5) is 1111111011. C before C23 has no binary format in printf, so code there tests each bit in a loop.

Decimal to binary resources

Decimal to binary FAQ

How do I convert a decimal to binary?

Divide the number by 2 and write down the remainder, 0 or 1. Divide the answer by 2 again, until it is 0. The remainders, read from the bottom up, are the binary number.

Paste a number here and open Steps to see each division for yours.

What is 25 in binary?

25 is 11001. 25 ÷ 2 = 12 remainder 1, 12 ÷ 2 = 6 remainder 0, 6 ÷ 2 = 3 remainder 0, 3 ÷ 2 = 1 remainder 1, 1 ÷ 2 = 0 remainder 1. From the bottom up: 11001. Check: 16 + 8 + 1 = 25.

How do I write "I love you" in binary?

Each letter has a number, its ASCII code, and that number is written in 8 bits. I is 73, space 32, l 108, o 111, v 118, e 101, y 121, u 117. So "I love you" is:

01001001 00100000 01101100 01101111 01110110 01100101 00100000 01111001 01101111 01110101

To do it here, paste the codes one per line, and turn on Signed 8-bit to get all 8 bits with the zeros in front.

How do I write a negative number in binary?

Computers use two's complement in a fixed number of bits. For -5 in 8 bits: write 5 (00000101), flip every bit (11111010), then add 1: 11111011. Set Signed to 8, 16, 32 or 64 bits and the tool does this, and Steps shows it.

With Signed off, the tool keeps the minus sign: -5 is -101.

Why is 0.1 not exact in binary?

Because 1/10 cannot be made from halves, quarters and eighths. In binary 0.1 is 0.000110011001100... with 0011 repeating forever, just as 1/3 is 0.333... in decimal. Code must cut it somewhere, which is why 0.1 + 0.2 gives 0.30000000000000004. The tool shows where the digits repeat.

How many bits does a number need?

The Max bits figure at the top shows it for the largest number in your list, and Summary says which width it fits: 255 needs 8 bits, 65,535 needs 16, and 4,294,967,295 needs 32. To pad a number to a full width, set Signed to that width.

Are my numbers sent anywhere?

No. The numbers are converted in your browser, with JavaScript BigInt. Nothing is uploaded, and there are no ads or cookie walls. You can check this in your browser's network tab while you use it.