What is Decimal to Binary Number Converter?
decimal to binary, two's complement This tool runs entirely in your browser. No data is sent to any server, and no signup is needed.
Decimal to Binary Converter
Decimal to binary conversion via repeated division by 2. Foundation of digital computing.
About decimal to binary conversion
Decimal to binary conversion rewrites a base-10 integer as a string of 0s and 1s in base-2, the native representation used inside every digital computer. Each bit is a power of 2, switched on or off, and the sum of the active powers reconstructs the original number.
How it works: positional notation and division by 2
Binary uses positional notation just like decimal, but each position is a power of 2 instead of 10. The rightmost bit is 2^0 = 1, then 2^1 = 2, 2^2 = 4, 2^3 = 8, and so on. A binary number 1011 means 1 times 8, plus 0 times 4, plus 1 times 2, plus 1 times 1 = 11 decimal.
N = b_k * 2^k + b_(k-1) * 2^(k-1) + ... + b_1 * 2 + b_0
algorithm:
while N > 0:
bit = N mod 2 # remainder is 0 or 1
N = N // 2 # integer division
push bit to output
read output in reverse
- N = the decimal integer you want to convert.
- b_i = the bit (0 or 1) at position i, where position 0 is the rightmost (least significant) bit.
- mod 2 = the remainder after dividing by 2, which is the next bit.
- // 2 = integer division by 2, dropping the remainder, which shifts the number right by one bit.
- Bits are produced low-to-high but written high-to-low, so the output stack must be reversed.
Worked example: convert 156 to binary
Apply the division-by-2 algorithm step by step. Each row records the quotient and the remainder, and the remainders read bottom-up form the answer.
- 156 / 2 = 78 remainder 0
- 78 / 2 = 39 remainder 0
- 39 / 2 = 19 remainder 1
- 19 / 2 = 9 remainder 1
- 9 / 2 = 4 remainder 1
- 4 / 2 = 2 remainder 0
- 2 / 2 = 1 remainder 0
- 1 / 2 = 0 remainder 1
- Read remainders bottom to top: 1 0 0 1 1 1 0 0.
Reference: powers of 2 and small decimal-to-binary table
Memorising the first 16 powers of 2 and the first 16 binary numbers lets you convert most everyday values in your head.
| Power | Decimal value | Common use |
|---|---|---|
| 2^0 | 1 | 1 bit |
| 2^1 | 2 | flag pair |
| 2^2 | 4 | 2-bit range |
| 2^3 | 8 | 1 byte halved |
| 2^4 | 16 | 1 nibble (hex digit) |
| 2^7 | 128 | signed byte limit |
| 2^8 | 256 | 1 byte total range |
| 2^10 | 1,024 | 1 KiB (kibibyte) |
| 2^16 | 65,536 | 1 word (Unicode BMP) |
| Decimal | Binary (4 bits) | Decimal | Binary (4 bits) |
|---|---|---|---|
| 0 | 0000 | 8 | 1000 |
| 1 | 0001 | 9 | 1001 |
| 2 | 0010 | 10 | 1010 |
| 3 | 0011 | 11 | 1011 |
| 4 | 0100 | 12 | 1100 |
| 5 | 0101 | 13 | 1101 |
| 6 | 0110 | 14 | 1110 |
| 7 | 0111 | 15 | 1111 |
Common pitfalls
- Reading remainders the wrong way. The first remainder you compute is the least significant bit. Read remainders bottom-up, not top-down, or your answer will be bit-reversed.
- Forgetting to pad with leading zeros. A byte is 8 bits. The number 5 is 101 in pure binary but 00000101 as a byte. APIs and file formats almost always expect the padded form.
- Confusing signed and unsigned ranges. 11111111 means 255 unsigned but minus 1 in two's complement signed. Always confirm which encoding the system expects.
- Floating-point rounding. Decimal fractions like 0.1 have no finite binary expansion, so 0.1 + 0.2 returns 0.30000000000000004 in most languages. Use integer cents for currency.
- Off-by-one bit count. floor(log2(N)) + 1 gives the bit count for unsigned N greater than zero. The number 0 still needs one bit (the bit value 0).
Related tools and glossary
Frequently asked questions
How do I convert 156 to binary by hand?
Use division by 2 and read remainders bottom-up. 156/2 = 78 r 0; 78/2 = 39 r 0; 39/2 = 19 r 1; 19/2 = 9 r 1; 9/2 = 4 r 1; 4/2 = 2 r 0; 2/2 = 1 r 0; 1/2 = 0 r 1. Reading bottom to top: 10011100. Verify by adding the powers of 2: 128 + 16 + 8 + 4 = 156.
How many bits do I need to store a decimal number?
floor(log2(N)) + 1 bits for an unsigned integer N. Examples: 100 needs 7 bits (max 127), 1,000 needs 10 bits (max 1023), 1,000,000 needs 20 bits (max 1,048,575). For signed two's complement, add one bit for the sign.
What is the largest 8-bit unsigned number?
11111111 binary = 255 decimal (2^8 minus 1). For signed two's complement, the range is -128 to 127 (10000000 to 01111111). 16-bit unsigned reaches 65,535, 32-bit unsigned reaches 4,294,967,295.
What is two's complement and why use it?
Two's complement is the standard way computers store negative integers. To negate a number, invert all bits and add 1. Example: -5 in 8 bits is 00000101 inverted = 11111010, plus 1 = 11111011. It works because addition of a number and its negation wraps around to zero with one shared zero representation, which simplifies CPU arithmetic circuits.
Sources
- Knuth, Donald (1997) The Art of Computer Programming, Vol 2: Seminumerical Algorithms, Section 4.1 - positional number systems and radix conversion.
- IEEE 754-2019 standard for floating-point arithmetic - binary fraction representation.
- Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 1, Section 4.2 - signed integer encoding and two's complement.
