Skip to content
PC Moment

Free tool

Decimal to Binary Converter

Convert a decimal number to binary with the repeated division by 2 shown, pad it to 8, 16, 32 or 64 bits, and see negative numbers in two's complement.

Binary
–
Octal
–
Decimal
–
Hex
–

Converting decimal to binary is the classic exercise of every intro programming and networking course, and a practical need when you work with bit flags, subnet masks or register values. This converter shows the repeated division by 2 that produces the bits, and can pad the result to a fixed width of 8, 16, 32 or 64 bits. With a width chosen, it also shows negative numbers the way computers store them: in two’s complement.

How to use the decimal to binary converter

  1. Type the decimal number. Spaces and underscores are ignored, so 1_000_000 works.
  2. Leave Convert from set to decimal. You can switch to binary, octal or hex at any time.
  3. Optionally, pick a width under Pad the binary result to: 8, 16, 32 or 64 bits. The binary result is padded with leading zeros to that width.
  4. For a negative number, choose a width to see it in two’s complement at that width.
  5. Read the binary result, plus the octal and hex forms, and follow the division steps underneath. Use the copy button to copy any result.

How it works

Repeated division by 2

To turn a whole number into binary, divide it by 2 and keep the remainder, which is always 0 or 1. Divide the quotient by 2 again, and repeat until the quotient is 0. The remainders are the bits, from the lowest to the highest, so you read them from the bottom up.

Two’s complement for negative numbers

Most computers store signed integers in two’s complement at a fixed width. To get the pattern for −n:

  1. Write n in binary at the chosen width.
  2. Invert every bit (0 becomes 1, 1 becomes 0).
  3. Add 1.

The result is the same as 2^width − n. MDN’s JavaScript reference uses the same representation: its bitwise NOT example shows −3 as thirty 1 bits followed by 01 in 32 bits, and it notes that BigInt values are encoded as two’s complement. The leftmost bit acts as the sign: 1 means negative.

A number has to fit in the width you choose. In 8 bits, signed values run from −128 to 127 and unsigned values from 0 to 255; in 16 bits, from −32,768 to 32,767 and 0 to 65,535.

Worked examples

13 → 1101

DivisionQuotientRemainder
13 ÷ 261
6 ÷ 230
3 ÷ 211
1 ÷ 201

Reading the remainders from the bottom up gives 1101. Check: 8 + 4 + 1 = 13. Padded to 8 bits it is 00001101.

156 → 10011100

DivisionQuotientRemainder
156 ÷ 2780
78 ÷ 2390
39 ÷ 2191
19 ÷ 291
9 ÷ 241
4 ÷ 220
2 ÷ 210
1 ÷ 201

Bottom up: 10011100. Check: 128 + 16 + 8 + 4 = 156.

1000 → 1111101000

Ten divisions give the remainders 0, 0, 0, 1, 0, 1, 1, 1, 1, 1; read backward that’s 1111101000 (512 + 256 + 128 + 64 + 32 + 8 = 1,000). In hex it is 3E8.

−5 in 8 bits → 11111011

5 in 8 bits is 00000101. Invert every bit: 11111010. Add 1: 11111011. Check: 2⁸ − 5 = 251, and 11111011 is 251 read as unsigned. At 16 bits the same number is 1111111111111011.

−100 in 8 bits → 10011100

100 is 01100100; inverted, 10011011; plus 1, 10011100. That’s the same bit pattern as 156 above, because 256 − 100 = 156: whether those bits mean 156 or −100 depends on whether the program treats them as unsigned or signed.

Common values

DecimalBinaryPadded to 8 bits
1100000001
10101000001010
127111111101111111
2551111111111111111
−1−111111111 (two’s complement)
−128−1000000010000000 (two’s complement)

Note that 255 and −1 share the same 8-bit pattern: as with 156 and −100, only the signed or unsigned reading tells them apart.

Frequently asked questions

How do you convert decimal to binary by hand?

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 13 that gives 1101.

What is 255 in binary?

11111111, eight 1 bits. 255 is 2^8 − 1, the largest number one byte can hold.

How are negative numbers written in binary?

Computers usually use two's complement: write the positive number at a fixed width, invert every bit and add 1. In 8 bits, −5 is 11111011. Pick a width in the converter to see it.

Why do I have to choose a width for negative numbers?

Two's complement depends on the width: −1 is 11111111 in 8 bits but sixteen 1s in 16 bits. Without a width the converter shows the binary digits with a minus sign in front.

Can I convert decimal fractions like 0.1?

No. The converter handles whole numbers of any size, but not fractions.

Related guides

PC Moment title card for Binary to Decimal Converter

Free tool

Binary to Decimal Converter

Convert a binary number to decimal and see which powers of 2 add up to the result. Hex and octal are shown too.

Free calculator

PC Moment title card for Hex to Decimal Converter

Free tool

Hex to Decimal Converter

Convert a hexadecimal number to decimal and see the working digit by digit. Binary and octal are shown too, for numbers of any length.

Free calculator

Free Developer and PC Tools

Free formatters, decoders and converters for developers and PC users. Everything runs in your browser, and nothing you type is sent anywhere.

2 min read