Free decimal to binary converter that shows the working
Decimal to binary, one division at a time
Type a whole number and its binary form appears together with the arithmetic that produced it: a divide-by-two table whose remainders, read from the bottom up, are the answer. It is free, there is nothing to sign up for, and every bit is labelled with the power of two it stands for, so 1234 reads as 1024 + 128 + 64 + 16 + 2. Choose a width of 8, 16, 32 or 64 bits to see the padded form, have overflow flagged when the value will not fit, and — for a negative number — watch the invert-and-add-one that builds its two's complement. Everything is computed with BigInt, so numbers far past 2⁵³ keep every digit.
- 100% free
- No signup
- Every division shown
- 8/16/32/64-bit
- Two's complement
Binary
100 1101 0010
- Bits used
- 11
- Hex
- 0x4D2
- Octal
- 0o2322
- Decimal
- 1,234
Stored in 16 bits: 0000 0100 1101 0010
Bit positionsclick any bit to flip it and watch the number change
1,234 = 1,024 + 128 + 64 + 16 + 2
Divide by two, keep the remainders11 divisions, read bottom to top
| Step | Division | Quotient | Remainder |
|---|---|---|---|
| 1 | 1234 ÷ 2 | 617 | 0 |
| 2 | 617 ÷ 2 | 308 | 1 |
| 3 | 308 ÷ 2 | 154 | 0 |
| 4 | 154 ÷ 2 | 77 | 0 |
| 5 | 77 ÷ 2 | 38 | 1 |
| 6 | 38 ÷ 2 | 19 | 0 |
| 7 | 19 ÷ 2 | 9 | 1 |
| 8 | 9 ÷ 2 | 4 | 1 |
| 9 | 4 ÷ 2 | 2 | 0 |
| 10 | 2 ÷ 2 | 1 | 0 |
| 11 | 1 ÷ 2 | 0 | 1 |
The last remainder is the leading bit, the first remainder is the last bit — so reading the column upwards spells 100 1101 0010. Each division asks the same question, whether what is left is odd, and each answer is worth twice the one before it.
How to convert a decimal number to binary
Enter the number, pick the width, and read the arithmetic that gets you there.
Enter the number
Type any whole number, or paste one — underscores, commas and spaces inside it are ignored, so a figure lifted out of a spreadsheet or a source file needs no tidying first. Put a minus in front for a negative value and the two's-complement working appears; the Negative button loads −42 if you would rather just look at one.
Choose how wide the register is
Auto uses the fewest bits the number actually needs, which is the plain answer to the question. Pick 8, 16, 32 or 64 instead and the value is shown padded into that many bits, with a warning if it does not fit and the wrapped value it would become if you stored it anyway. Every bit in the grid is a button: click one to flip it and the decimal number updates, which is the fastest way to feel what each position is worth.
Follow the arithmetic underneath
The division table halves the number over and over, keeping each remainder, and reading that remainder column from the bottom upwards spells the binary result — the algorithm you would use on paper, with every step visible instead of implied. Above it, the set bits are added together as powers of two, and for a negative number a three-row table shows the magnitude, every bit inverted, and the plus one that lands on the answer.
Technical specifications
| Input range | Any whole number, positive or negative, up to 2,000 digits — 18,446,744,073,709,551,615, the largest unsigned 64-bit value, converts in well under a millisecond |
|---|---|
| Working shown | One table row per division, all of them up to 64 rows; longer numbers keep the first 12 and last 12 and count the rest, and the table is skipped entirely past 2,048 bits |
| Bit labelling | Every bit tagged with its exponent, and its place value shown when it is set; the set bits are added up as well — 1234 = 1024 + 128 + 64 + 16 + 2 |
| Widths | Auto, 8, 16, 32 and 64 bits, where Auto takes the narrowest of the four that holds the value; each bit in the grid is clickable and flipping one rewrites the decimal number |
| Overflow | Flagged with the number of bits actually needed and the value the register would wrap to — 300 written into 8 bits reads 00101100, which is 44 |
| Negative numbers | Two's complement built in three visible stages — the magnitude, every bit inverted, then plus one — with the resulting hex pattern |
| Signed ranges | −128 to 127 at 8 bits, −32,768 to 32,767 at 16, −2,147,483,648 to 2,147,483,647 at 32, and −9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 at 64 |
| Processing location | Your browser — the number you type is never sent anywhere, and the page keeps working offline |
Frequently asked questions
How do you convert decimal to binary by hand?
Divide by two over and over, write down each remainder, and read the remainders from last to first. Take 42: halving gives 21 remainder 0, then 10 remainder 1, then 5 remainder 0, then 2 remainder 1, then 1 remainder 0, then 0 remainder 1 — read upwards, that is 101010. The method works because every division asks the same question, whether what is left is odd, and each answer is worth twice the one before it. The other direction is quicker mentally: subtract the largest power of two that fits, put a 1 in that column, and repeat.
What is two's complement for?
It lets one piece of hardware do both addition and subtraction. Under two's complement the top bit carries a negative weight, so adding the bit patterns for −3 and 5 with the ordinary addition circuit gives 2 with no special case for the sign, and subtraction becomes addition of the complement. The alternatives were tried and abandoned: sign-magnitude and one's complement each have two representations of zero, so a comparison against zero needs two tests, and one's complement addition needs an end-around carry that adds a whole extra pass. Two's complement has exactly one zero, no extra hardware, and it is now so universal that C++20 and C23 stopped allowing anything else.
Why does a signed 8-bit number run from −128 to 127 rather than −127 to 127?
Because there is no negative zero to waste. The 256 available patterns split into 128 with the top bit clear, which are 0 to 127, and 128 with it set, which are −128 to −1 — an asymmetric range with one more negative value than positive. That extra value causes a real bug class: negating −128 in 8 bits, or −2,147,483,648 in 32, overflows back onto itself, so Math.abs of the most negative integer returns the same negative number in most languages, and dividing it by −1 traps on x86.
What happens when the number does not fit the width I chose?
The high bits are discarded and the value wraps, which is arithmetic modulo 2 to the power of the width. Storing 300 in 8 bits leaves 00101100, which reads back as 44, because 300 − 256 = 44; storing 255 + 1 leaves zero. This page flags that instead of hiding it, showing how many bits the number really needs beside the value the register would hold. The classic public example is YouTube's view counter, which was a signed 32-bit integer capped at 2,147,483,647 until Gangnam Style got close enough in 2014 that Google moved it to 64 bits.
Can it convert a decimal fraction such as 12.75?
No — this page halves whole numbers, and fractions use the mirror-image method: multiply the fractional part by two repeatedly and record the integer part of each result, reading downwards. That gives 12.75 as 1100.11, because .75 doubles to 1.5 (write 1) and the remaining .5 doubles to 1.0 (write 1, and stop). Most decimal fractions never stop: a tenth becomes 0.0001100110011… forever, which is why 0.1 has no exact binary form and why floating-point arithmetic surprises people. Round to a whole number of units — cents, milliseconds, pixels — before converting.
How many bits do I need for a particular number?
Take the base-2 logarithm and round down, then add one: an n-bit unsigned field holds 0 to 2ⁿ − 1. In practice you can count decimal digits and multiply by 3.32, since each decimal digit carries log₂10 bits — a 6-digit number needs about 20 bits, and 255 needs 8 while 256 needs 9. For a signed value add one more bit for the sign, so storing −1,000 takes 11 bits rather than 10. The bit count is shown here beside every result, which is usually all you need to pick between a 16-bit and a 32-bit column.
Why is binary written in groups of four?
Because four bits are exactly one hex digit, so the grouping converts the two notations by eye. 1101 0010 reads as D2 without any arithmetic, and once the habit is there a 32-bit pattern becomes eight familiar symbols rather than thirty-two identical ones. Groups of eight mark byte boundaries and are the other common choice, particularly in network diagrams and register maps where what matters is which byte a bit lives in.
About binary representation
Base 2 is not a special notation, it is the ordinary one with a smaller alphabet. In any base, a numeral is a sum of digits multiplied by powers of the base — 1234 in decimal is 1×10³ + 2×10² + 3×10¹ + 4×10⁰ — and binary simply uses powers of two, so 10011010010 is 1024 + 128 + 64 + 16 + 2. Halving repeatedly is that definition run backwards: each division peels off the units bit as its remainder and shifts the rest down one place. Hardware settled on two digits because a circuit only has to distinguish two states reliably, which it can do across wide swings of voltage, temperature and age; a ten-state circuit was tried in the 1950s and lost decisively on noise tolerance.
Negative numbers were the harder design problem, and two's complement is the answer that won. Early machines used sign-magnitude, where one bit records the sign and the rest the size, or one's complement, where negation flips every bit; both give you two zeros, a positive and a negative one, and one's complement needs an end-around carry to make addition work. Two's complement defines the negative of a value as whatever must be added to it to overflow the register back to zero, which is exactly what inverting and adding one produces. The payoff is that the same adder handles both signs, comparison against zero is one test, and the only wrinkle left is the asymmetric range: 8 bits hold −128 but not +128. It is now the only representation the C++20 and C23 standards permit for signed integers.
Width is where binary stops being theory. JavaScript looks like a language without integer widths, and then every bitwise operator coerces its operands to signed 32-bit — which is why 1 << 31 is −2,147,483,648 rather than 2,147,483,648, and why x | 0 is a truncation rather than a no-op. Above 2⁵³ plain numbers stop being able to name consecutive integers at all, and you need BigInt with BigInt.asIntN to work at a chosen width on purpose. When you are reading bits rather than writing them, four at a time is easier: the hex inspector takes the same values from the other side, and if the bytes turn out to be text rather than a number, the ASCII table has the code for each character in all four bases.
Where the arithmetic happens
Every division, inversion and carry on this page is computed by JavaScript inside your own browser. Nothing you type is transmitted, logged or stored, so the tool behaves the same on an air-gapped laptop as it does online — and once the page has loaded you can drop the connection entirely and keep converting.