How to Convert Decimal to Binary
Convert decimal to binary with repeated division by 2 or subtracting powers of 2, plus negative numbers and decimal fractions, with worked examples.
How to Convert Decimal to Binary
You are staring at a decimal 156 and your exam paper demands its binary form. The clock is ticking, and the divide-by-2 method is the fastest route. Here is exactly how to convert decimal to binary by hand, using two reliable methods, and then the tricky cases: negative numbers, fractions, and the overflow that bites you in two's complement. You will leave with a method you can trust at 2 a.m. in an exam hall, not just a rule you memorized yesterday.
Method 1: Repeated Division by 2
The divide-by-2 method is the one most teachers show first, since it works for any whole number and is hard to get wrong if you write down every step. Write your decimal number, then divide it by 2. Record the quotient and the remainder. The remainder is always 0 or 1, as you are dividing by 2. Repeat the division on the quotient, not on the original number, until the quotient becomes 0. Then read the remainders from the last one you wrote up to the first. That string of remainders is the binary representation.
Take 13. Divide 13 by 2: quotient 6, remainder 1. Divide 6 by 2: quotient 3, remainder 0. Divide 3 by 2: quotient 1, remainder 1. Divide 1 by 2: quotient 0, remainder 1. Read the remainders upward: 1101. Check it: 8 + 4 + 0 + 1 = 13. The method never fails for a positive whole number. The only error that creeps in is reading the remainders in the wrong order, so circle the last remainder you write and read from there.
Method 2: Subtract Powers of 2
The second method is faster when you already know your powers of 2 by heart, and it doubles as a decimal-to-binary conversion check. List the powers of 2 from the largest that fits your number down to 1: 128, 64, 32, 16, 8, 4, 2, 1 for an 8-bit result. For each power, ask: does it fit in the remaining value? If yes, write a 1 and subtract it; if no, write a 0 and move to the next power.
Convert 156 with this method. The largest power of 2 up to 156 is 128, so you write 1 and subtract: 156 - 128 = 28. Next is 64, which does not fit in 28, so write 0. Then 16 fits: 28 - 16 = 12, write 1. Then 8 fits: 12 - 8 = 4, write 1. Then 4 fits: 4 - 4 = 0, write 1. The remaining powers 2 and 1 get 0s. Reading left to right: 1 0 0 1 1 1 0 0, which is binary 10011100. The two methods agree, and that agreement is your first check. If you get different answers, one of them is wrong, so redo both.
Worked Examples: From 0 to 255
Work through a few more so the pattern sticks. Convert 42. Division by 2: 42/2=21 rem 0, 21/2=10 rem 1, 10/2=5 rem 0, 5/2=2 rem 1, 2/2=1 rem 0, 1/2=0 rem 1. Reading upward: 101010. Check: 32+8+2=42. Now convert 255. Division gives you eight 1s: 11111111, which is 128+64+32+16+8+4+2+1=255. That is the maximum value for an 8-bit unsigned number. One more: convert 100. […] Read upward: 1100100. Check: 64+32+4=100. Each of these examples is a decimal-to-binary conversion you can do in under a minute with either method.
Negative Decimals: Two's Complement
Negative numbers change everything. The standard representation on virtually all modern CPUs is two's complement, where the most significant bit has a negative weight. […] Then invert every bit: 11110010. Then add 1: 11110011. That is -13. The rule is 'invert and add one', and it works because -x = (~x) + 1 in two's complement. The range for 8-bit two's complement is -128 to 127, not -127 to 127, because the all-ones pattern 10000000 represents -128.
The failure case appears when you widen a value. If you have an 8-bit -1, which is 11111111, and you copy it into a 16-bit variable without sign-extending, you get 0000000011111111, which is 255, not -1. […] In C, the right shift of a negative signed value is implementation-defined per C17 clause 6.5.7, though GCC and Clang both perform arithmetic shifts that preserve the sign. […] Do not assume every language behaves the same, and test before you rely on it.
Decimal Fractions to Binary: Multiply by 2
What about 13.25? […] Read the digits in the order you produced them: 01. So 13.25 in binary is 1101.01, which is 8+4+1+0.25.
Not every fraction terminates. Try 0.1. […] So 0.1 in binary is an infinitely repeating pattern 0.0001100110011..., which is why floating-point arithmetic cannot represent 0.1 exactly. If your exam asks for a fixed number of bits, you stop after that many digits and round or truncate, but know that the representation is approximate for many fractions.
Binary Arithmetic: Addition, Subtraction, Multiplication, Division
Once you have the binary, you can do arithmetic directly.Add -128 and -1: 10000000 + 11111111 = 101111111, truncated to 8 bits is 01111111, which is 127, also overflow. Add -1 and 1: 11111111 + 00000001 = 100000000, truncated to 00000000, which is 0, no overflow. Subtraction is addition of the two's complement: binary 1000 (8) - 0001 (1) = 0111 (7), because you add the two's complement of 0001, which is 1111, to 1000, getting 10111, truncated to 0111.
Multiplication uses shifts and adds of […] Integer division truncates toward zero in C99 and later, so -7/2 is -3, not -4. […] In the 127+1 example, there is a carry out of the top bit, and overflow is set because the sign flips.
Bitwise Operations and Shifts
Bitwise AND, OR, XOR, and NOT operate on each bit independently. […] Bitwise NOT of 4-bit 1010 (decimal 10) is 0101 (decimal 5), because NOT inverts each bit. […] Left shift by one bit is always equivalent to multiplication by two, barring overflow, so 00000101 (5) << 1 = 00001010 (10). […] right shift of a signed negative value in C is implementation-defined, though most compilers do arithmetic. […] A rotation wraps the bits around instead of shifting in zeros, which is useful in cryptography but not in standard C.
Checking Your Work Without a Calculator
You can verify any decimal to binary conversion by reversing the process. For each 1 in the binary, add the corresponding power of 2. […] For addition and subtraction, do the arithmetic in decimal on the original numbers and compare the result. […] For division, check that quotient times divisor plus remainder equals the dividend. The fastest cross-check for a hand conversion is to convert back using the powers-of-2 table, which takes ten seconds and catches the most common error, reading remainders in the wrong order.
Common Questions
What is the fastest way to convert decimal to binary by hand?
For a single number, the subtract-powers-of-2 method is usually faster if you know the powers of 2. For a batch of numbers, repeated division by 2 is more systematic and less error-prone because you only divide by 2 and track remainders.
How do I convert a negative decimal number to binary?
Use two's complement. Convert the absolute value to binary, pad to your bit width, invert all bits, then add 1. For -13 in 8 bits, start with 00001101, invert to 11110010, add 1 to get 11110011.
Why does 0.1 in binary not terminate?
Because 0.1 in decimal is 1/10, and 10 has a prime factor of 5, but binary only has the factor 2. […] This is why floating-point numbers cannot represent 0.1 exactly.
What is the difference between a carry and an overflow flag?
The carry flag indicates an unsigned result that does not fit in the destination width, such as […] you can have one without the other.
How do I right-shift a negative number portably in C?
The C standard says right shift of a negative signed value is implementation-defined. […] Cast to an unsigned type first, perform a logical shift, then cast back, or use division by a power of two if you want arithmetic behavior, but be aware that division truncates toward zero, not toward negative infinity.