Decimal to Binary Converter_
Halve your way to binary: this converter runs the divide-by-2 method live and lists every quotient and remainder, so the answer arrives together with the reasoning. Add a 0b prefix or nibble grouping for code, and let the Width setting zero-pad to a real register size.
Negatives become genuine two's-complement bit patterns once you pick a width, big values stay exact past the point where float tools quietly fail, and fractional input gets an honest explanation instead of twenty rounded bits.
- Input
- A whole decimal number, positive or negative, with spaces or underscores between digit groups if they help you read it.
- Output
- The binary value, optionally with an 0b prefix, nibble grouping, or zero-padding to a register width — plus the hexadecimal equivalent as a cross-check.
- Processing
- Halved in this tab with BigInt arithmetic, and every quotient and remainder in the chain is printed rather than summarised.
- Limits
- Ten thousand digits in. Whole numbers only: a decimal fraction is refused with the reason, because almost none of them have a finite binary form.
- Negatives
- A minus sign alone gives you −1011, which is arithmetic on paper. Choose a Width and you get the pattern memory actually stores: −11 is 11110101 in a byte.
Decimal to binary with the halving written out
The divide-by-2 method on 173
The method is two instructions long: keep halving, keep the remainders. 173 ÷ 2 is 86 remainder 1; 86 ÷ 2 is 43 remainder 0; then 21 r 1, 10 r 1, 5 r 0, 2 r 1, 1 r 0, 0 r 1. Reading the remainders from the last to the first: 10101101. As a formula: the next bit is always n mod 2, and n ÷ 2 (floored) carries on — repeat until n is zero. The panel under the converter prints this exact ladder for anything you type, so you can learn the procedure on a number whose answer you already trust.
Reading the answer back
Every conversion can be checked in the other direction: each 1 in the output claims a power of two, and the claims must add back to your input. For 10101101: 128 + 32 + 8 + 4 + 1 = 173. The place-value table below lists the first sixteen powers for exactly this purpose, and the hexadecimal readout under the result gives a third cross-check — AD for 173, since every four bits collapse into one hex digit.
Negatives: pick a width, get a bit pattern
Typing -11 yields -1011, which is arithmetic on paper but not something memory can hold — hardware stores negatives as two's complement inside a fixed number of bits. Set the Width control and the page produces that stored form: −1 at 8 bits is 11111111, −128 is 10000000, and −11 is 11110101. Positives gain zero-padding to the same width, which is what fixed-width protocol fields and register maps expect, and anything that can't fit the chosen size fails with the allowed range spelled out.
Fractions, floating point, and the tools in your editor
Fractions use the mirror method — multiply by 2 and collect the whole-number bits: 0.1 × 2 = 0.2 (bit 0), 0.4 (0), 0.8 (0), 1.6 (1, keep 0.6), 1.2 (1, keep 0.2)… and the 0011 pattern now cycles forever: 0.000110011…. Only fractions with power-of-two denominators terminate, which is precisely why 0.1 + 0.2 ≠ 0.3 in every language that uses IEEE floats — the inputs were never stored exactly to begin with. This page therefore converts whole numbers and says so, rather than truncating a repeating expansion behind your back. In your own tooling: Excel's =DEC2BIN(173) works only from −512 to 511 (a 10-bit window), while Python's bin(173) and format(173, "08b") handle any size, the latter zero-padding like the Width control here.
Type a number, follow the ladder, pick a width
- 01Type the decimal value — digit grouping with spaces or underscores is welcome, and it re-runs on every keystroke.
- 02Follow the ÷2 ladder in the panel below the result: quotient and remainder per row, collected bottom-up. It is the same table an exam question asks you to produce, which makes it the fastest way to check your own working.
- 03Dress the output for its destination: 0b prefix for source code, nibble grouping for readability, or a Width (8/16/32/64) for zero-padded, register-shaped output — negatives included, as two’s complement.
- 04Copy_Result when it looks right, cross-check via the hexadecimal readout, or flip directions with the Binary → decimal link.
Four numbers worth converting, and why
Building a bitmask
Flag value 173 in a config — which feature bits are on? The binary form is the answer sheet: bits 0, 2, 3, 5, and 7.
173
10101101
IPv4 octet, bit by bit
Subnetting practice means seeing 192 as bits. Width 8 keeps every octet eight digits long, leading zeros included.
192
11000000
GPIO / seven-segment pattern
A display driver wants the segment pattern as one byte. 118 lights the segments for a digit — grouped output makes the wiring readable.
118
0111 0110
A negative offset for firmware
A calibration offset of −11 must be written into a signed byte. Two's complement at 8 bits is the pattern the register stores.
-11
11110101
Decimal → binary, 0 through 16
| Decimal | Binary | Decimal | Binary |
|---|---|---|---|
| 0 | 0 | 9 | 1001 |
| 1 | 1 | 10 | 1010 |
| 2 | 10 | 11 | 1011 |
| 3 | 11 | 12 | 1100 |
| 4 | 100 | 13 | 1101 |
| 5 | 101 | 14 | 1110 |
| 6 | 110 | 15 | 1111 |
| 7 | 111 | 16 | 10000 |
| 8 | 1000 |
Powers of two are the milestones: each one adds a digit (2→10, 4→100, 8→1000, 16→10000), and everything between is a combination of the milestones already passed.
Landmarks and what they say about width
| Decimal | Binary | Width implication |
|---|---|---|
| 64 | 1000000 | 7 digits — bit 6 alone |
| 127 | 1111111 | Top of a signed byte (7 value bits) |
| 128 | 10000000 | 8 digits begin; the sign bit position in a byte |
| 255 | 11111111 | A full unsigned byte |
| 256 | 100000000 | 9 digits — one byte no longer holds it |
| 1,024 | 10000000000 | 2¹⁰: the kibi step (1 KiB) |
| 65,535 | 1111111111111111 | Sixteen ones: two bytes full |
Digits needed ≈ log₂ of the value, rounded up — 173 sits between 128 and 255, so it takes 8 digits. Crossing a power of two is what grows the output by one digit.
Small habits that prevent bit-level bugs
- Doing the ladder by hand, halve with confidence: odd number → remainder 1, even → 0. You only ever need to know whether the current value is odd.
- Add up the 1-bits’ place values afterward — if they don’t rebuild your original number, a remainder got dropped somewhere in the ladder.
- Turn on Width for anything destined for a protocol field or register: fixed-size output with leading zeros is the form comparisons and concatenations expect.
- The hexadecimal readout is your compression check: every 4 binary digits should collapse into exactly one hex digit — AD for 10101101.
- For sign work, remember the two ceilings: 8 bits carry 0–255 unsigned but only −128–127 signed. Choosing the interpretation is choosing the ceiling.
- Suspicious of any converter? Feed it 9007199254740993 — if the binary doesn’t end in …0001, the tool rounds in floats and this page will disagree with it, correctly.
When the bits look right and are not
A minus sign is notation until you fix a width
−1011 exists on paper only. Hardware needs a container size before a negative has bits at all: −11 is 11110101 in a byte, 1111111111110101 in 16. The Width control is that decision made explicit — and the reason this page never guesses one for you.
Binary is not the same as binary-coded decimal
Ask for 173 in binary-coded decimal and you get 0001 0111 0011 — twelve bits spelling one, seven, three, a nibble per digit. Ask for it in binary and you get 10101101: eight bits encoding the value itself. Calculator displays, real-time-clock registers and some older financial formats want the first; this page produces the second. Writing one where the other is expected corrupts silently rather than failing.
Leading zeros matter in fixed-width fields
As a number, 101 and 00000101 are equal. As a protocol field, checksum input, or register write, they are different strings — width is part of the contract. Convert with the Width set to the field size instead of padding by eye.
Eight bits end at 255 — or at 127
A byte holds 256 patterns. Spend them all on magnitude and you reach 255; reserve the top bit for sign and positives stop at 127. Overflow bugs live exactly at these edges, which is why the width errors here name the range that applies.
Most decimal fractions never terminate in binary
0.5 and 0.25 convert cleanly; 0.1 becomes 0.000110011… repeating without end. Any tool that prints a finite answer for 0.1 chose a cutoff silently. That repetition is the root of the famous 0.1 + 0.2 = 0.30000000000000004 — the error was in the storage, not the addition.
Float-based converters go quietly wrong past 2⁵³
Snapping an integer to the nearest value a double can hold does not fail loudly — it prints bits that look entirely reasonable and are wrong in the middle. A double-precision number stops holding every integer past 9,007,199,254,740,991, so converters that compute in floats emit plausible wrong answers above it. The arithmetic here is arbitrary-precision, and the first integer a double cannot represent — 9,007,199,254,740,993 — is pinned in the test suite.
Widths, exactness, and what this converter will not do
- Input
- Decimal digits, optional sign, spaces or underscores between groups; 10,000-digit ceiling
- Working panel
- The ÷2 ladder — quotient and remainder per row, bottom-up collection note — appears whenever the input is 10 digits or fewer
- Output options
- Optional
0bprefix · nibble (4-bit) grouping - Width control
- Off/8/16/32/64: zero-pads positives and encodes negatives as two's complement, rejecting values outside the width with the range named
- Fractions
- Declined by design with the multiply-by-2 method explained — repeating expansions are never silently truncated
- Arithmetic
- Arbitrary-precision integers; the 2⁵³+1 exactness landmark is a pinned test
- Readouts
- Binary primary · hexadecimal secondary as the 4-bits-per-digit cross-check
- Network
- None from tool code. A test sweep calls every function this page uses with
fetchandXMLHttpRequestreplaced by stubs that throw, so a stray request fails the build instead of shipping. Disconnect from the network and the page still works.
Questions about converting decimal to binary
What is the formula for decimal to binary?
There isn’t a closed formula — it’s a loop: the next bit is n mod 2, then continue with n divided by 2 (floored) until n reaches zero, reading the collected bits in reverse. The working panel prints each pass of that loop for your value.
Why do I read the remainders bottom-up?
The first halving extracts the lowest-order bit (whether the number is odd), so remainders emerge least-significant first. Reversing at the end puts the most significant bit where it belongs on the left.
How does a negative number convert?
Two ways: as notation (−1011) with Width off, or as a real bit pattern once you choose 8/16/32/64 bits — two’s complement, the form hardware stores. Without a width, a negative simply has no bit pattern to give.
Can it convert 0.1 or other decimal fractions?
No, deliberately: 0.1 has no finite binary form (0.000110011… repeats forever), so any finite output would be a silent approximation. The About section teaches the multiply-by-2 method and shows why this same fact produces floating-point’s 0.1 + 0.2 surprise.
What are the limits in Excel and Python?
Excel’s DEC2BIN only covers −512 through 511 — ten bits including sign — and errors beyond. Python’s bin() is unlimited, and format(n, "08b") adds the zero-padding; this page matches Python’s exactness with the Width control for padding.
Is this how I write text in binary?
Not quite — text goes through character codes first. The text to binary converter handles that pipeline (character → code → bits); this page converts one number. They meet in the middle: "A" is code 65, and 65 here is 1000001.