GameParticles
Numbers & units

Decimal to Binary: The Divide by 2 Method, Step by Step

Convert decimal to binary by dividing by 2 and reading the remainders from bottom to top. Includes a powers of two chart, worked examples and negative numbers.

Updated

To convert decimal to binary, divide the number by 2 repeatedly, writing down each remainder, until the quotient is 0. The binary number is the remainders read from bottom to top. For example, 13 gives remainders 1, 0, 1, 1, which read in reverse order make 1101.

The divide by 2 method

  1. Divide the decimal number by 2.
  2. Write down the remainder. It will always be 0 or 1.
  3. Replace the number with the quotient and repeat.
  4. Stop when the quotient reaches 0.
  5. Read the remainders from the last one you wrote to the first.

Worked example: convert 156.

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

Reading the remainder column from bottom to top gives 10011100. So 156 in decimal is 10011100 in binary.

Why it works

Each division by 2 asks one question: is the number odd or even? The remainder is the answer, and it is exactly the rightmost binary digit, the ones place. Dividing then throws that digit away and shifts everything one place to the right, so the next remainder is the twos place, then the fours place, and so on. You discover the bits from right to left, which is why you read them in reverse at the end.

The subtraction method

If you know your powers of two, there is a second method that builds the answer from left to right.

  1. Find the largest power of two that fits into the number. Write a 1.
  2. Subtract it.
  3. Move to the next smaller power of two. If it fits into what is left, write 1 and subtract it. If not, write 0.
  4. Continue down to 1.

For 156: 128 fits, leaving 28 (write 1). 64 does not fit (0). 32 does not fit (0). 16 fits, leaving 12 (1). 8 fits, leaving 4 (1). 4 fits, leaving 0 (1). 2 does not fit (0). 1 does not fit (0). The result is 10011100, the same as before.

This method is quicker for mental arithmetic with small numbers. The divide by 2 method is better for large numbers, because you never need a power of two bigger than 2.

Powers of two chart

PowerValuePowerValue
2^012^9512
2^122^101,024
2^242^112,048
2^382^124,096
2^4162^138,192
2^5322^1416,384
2^6642^1532,768
2^71282^1665,536
2^82562^324,294,967,296

The chart also tells you how many bits a number needs. A number smaller than 2^n fits in n bits. Since 156 is smaller than 256, it fits in 8 bits.

Common decimal to binary values

DecimalBinaryDecimalBinary
111610000
21032100000
31150110010
4100641000000
51011001100100
71111271111111
8100012810000000
10101025511111111
121100256100000000
1511111,0001111101000

Padding to a fixed width

Computers store numbers in fixed sizes, usually 8, 16, 32 or 64 bits. To fit a result to a width, add zeros on the left. Decimal 13 is 1101, and as one byte it is 00001101. Leading zeros never change the value, just as 0042 is still 42.

Negative numbers, briefly

A minus sign is not available inside a computer, so negative whole numbers are stored using two's complement. To write a negative number at a given width:

  1. Write the positive value in binary, padded to the full width.
  2. Flip every bit: each 0 becomes 1 and each 1 becomes 0.
  3. Add 1.

For -42 in 8 bits: 42 is 00101010. Flipped, that is 11010101. Adding 1 gives 11010110.

The width matters. The same -42 in 16 bits is 1111111111010110. An 8-bit two's complement number covers -128 to 127, and a 32-bit one covers -2,147,483,648 to 2,147,483,647. Reading these bit patterns back is covered in Binary to Decimal.

Decimal fractions

For the part after the decimal point, multiply by 2 instead of dividing. The whole number part of each result (0 or 1) is the next bit, and you carry on with the fraction that remains.

For 0.625: doubling gives 1.25, so the first bit is 1 and 0.25 remains. Doubling gives 0.5, so the next bit is 0. Doubling gives 1.0, so the last bit is 1 and nothing remains. The answer is 0.101.

Not every fraction ends. Decimal 0.1 becomes 0.000110011... with 0011 repeating forever. That is why 0.1 + 0.2 does not come out as exactly 0.3 in most programming languages.

Using the converter

In the Number Base Converter, type a number into the decimal field and the binary field fills in immediately, grouped in fours for readability, together with the octal and hexadecimal forms. A panel underneath shows the value padded to 8, 16 and 32 bits, which saves the padding step.

The decimal field accepts a leading minus sign. Negative numbers are shown as 32-bit two's complement, so -42 appears as 32 bits ending in 1101 0110, and the 8-bit row shows 11010110, matching the hand calculation above. The converter handles whole numbers within the 32-bit range and does not take fractions, so use the multiply by 2 method for those.

Long binary strings are easier to handle in base 16, where each group of four bits becomes one digit. What Is Hexadecimal explains how.

Try it

Enter 156 in the decimal field of the Number Base Converter and confirm the binary reads 1001 1100. Then try -42 and compare the 8-bit row against the flip and add 1 steps. The other number tools are in the numbers category.

Tools in this guide

Frequently asked questions

How do you convert decimal to binary?

Divide the number by 2 and write down the remainder, which is 0 or 1. Divide the quotient by 2 again and repeat until the quotient reaches 0. The binary number is the list of remainders read from the last one to the first.

What is 10 in binary?

Decimal 10 is 1010 in binary. Dividing by 2 gives remainders 0, 1, 0, 1, which read in reverse are 1010. You can check it with place values: one 8 plus one 2 equals 10.

How are negative numbers written in binary?

Most computers use two's complement. Write the positive value at a fixed width, flip every bit, then add 1. In 8 bits, 42 is 00101010, so -42 is 11010110. The leftmost bit ends up as 1 for every negative number.

How many bits do I need for a decimal number?

Find the smallest power of two that is larger than the number. Its exponent is the bit count. 156 is below 256, which is 2 to the power 8, so it needs 8 bits. Values up to 255 fit in 8 bits and values up to 65,535 fit in 16.

More numbers & units guides

JSON Formatter
Developer · Format, validate and minify JSON with syntax highlighting.
↵
Base64 Encode / Decode
Developer · Encode text to Base64 or decode Base64 back to plain text.
↵
URL Encoder / Decoder
Developer · Encode or decode URL components and query strings.
↵
Hash Generator
Developer · Generate MD5, SHA-1, SHA-256 and SHA-512 hashes.
↵
UUID Generator
Developer · Generate UUIDs v4 (random) in bulk with one click.
↵
Regex Tester
Developer · Test regular expressions against text with live match highlighting.
↵
Word Counter
Text · Count words, characters, sentences, paragraphs and reading time.
↵
Case Converter
Text · Convert text between UPPER, lower, Title, camelCase, snake_case and more.
↵
List Sorter
Text · Sort, reverse, deduplicate and shuffle lists of text.
↵
Markdown Preview
Text · Write Markdown and see a live rendered preview side by side.
↵
Percentage Calculator
Numbers · Calculate percentages, increases, decreases and what % one number is of another.
↵
Color Converter
Colors · Convert colors between HEX, RGB, HSL and HSV instantly.
↵
Snake
Arcade · Eat food, grow longer, don't hit the walls. A timeless classic.
↵
2048
Puzzle · Slide tiles and combine them to reach the legendary 2048 tile.
↵
Word Grid
Puzzle · Guess the hidden five letter word in six tries using color clues.
↵
Sudoku
Puzzle · Fill the 9x9 grid with logic. Four difficulties from easy to expert.
↵
Minesweeper
Strategy · Use number clues to clear the minefield. Classic logic, three levels.
↵
Breakout
Arcade · Smash every brick with paddle and ball. Power-ups, combos, endless levels.
↵
Typing Practice
Casual · Build your WPM and accuracy with timed drills from 30 seconds to 5 minutes. Find your weak keys.
↵
TypeRunner
Arcade · Multiplayer typing race. Race friends by link, beat computer runners, or chase your own ghost.
↵
Typing Blocks
Arcade · Type each word before its wooden block lands. Miss, and the pile climbs toward the line.
↵
Bubble Shooter
Arcade · Aim, bank shots off the walls, and pop groups of three or more bubbles.
↵
Road Rush
Arcade · Race seven rivals through traffic and punch your way to the front.
↵