Decimal ⇄ Binary Converter
Real-time. Bit grid visualizer. Signed 2's complement. IEEE 754.
DEC
1101
Binary (base 2)
1101
Hex (base 16)
D
Octal (base 8)
15
Signed 2's complement (32-bit)
00000000 00000000 00000000 00001101
Interactive bit grid — click bits to toggle = 13
IEEE 754 floating-point representation
Sign (1 bit) Exponent Mantissa
Powers of 2 — the value of each bit
Each active bit adds its power-of-2 value to the total. Bars in green are set to 1 in your current number.
Step-by-step division method
Divide by 2, record the remainder, repeat with the quotient. Read remainders from bottom to top to get the binary result.
| Division | Quotient | Remainder | Bit # |
|---|
How to use this decimal to binary converter
Type or paste a decimal number in the input field — the converter updates in real time as you type. It accepts positive integers, negative integers, decimals with fractional parts, and scientific notation such as 5.72e2. The output panel shows the value in binary, hexadecimal, octal, and signed two's complement at your chosen bit width. Below that, the bit-grid visualizer lets you click individual bits to see how each power of 2 contributes to the total.
Tap the circular swap icon to reverse direction and convert binary back to decimal. Change the bit width to see how the same number is stored as an 8-, 16-, 32-, or 64-bit integer, and switch grouping to break long binary strings into readable chunks of 4 or 8. Everything runs locally in your browser — nothing is uploaded, logged, or cached on a server.
What is decimal and what is binary?
Decimal is the base-10 numeral system. It uses ten symbols — 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 — and each position represents a power of 10. The number 653 means 6×10² + 5×10¹ + 3×10⁰. Humans use decimal because we have ten fingers.
Binary is the base-2 numeral system. It uses only two symbols — 0 and 1 — and each position represents a power of 2. The binary number 1101 means 1×2³ + 1×2² + 0×2¹ + 1×2⁰ = 8 + 4 + 0 + 1 = 13. Every digital computer stores and processes information in binary because it maps directly onto the two states of a transistor (on/off), which makes hardware simpler, faster and more reliable to build with logic gates (Calculator.net). Binary is the foundational language of computing — every image, sound, character and instruction in every device ultimately lives as a stream of ones and zeros.
The division-by-2 method (step by step)
The standard algorithm for converting decimal to binary is repeated division by 2. Divide the number by 2, record the remainder, replace the number with the quotient, and repeat until the quotient is 0. Read the remainders from bottom to top and you have the binary equivalent.
Convert 13 to binary
────────────────────
13 ÷ 2 = 6 remainder 1 ← bit 0 (LSB) 6 ÷ 2 = 3 remainder 0 ← bit 1 3 ÷ 2 = 1 remainder 1 ← bit 2 1 ÷ 2 = 0 remainder 1 ← bit 3 (MSB) Read bottom → top: 1101₂ = 13₁₀
The step-by-step division table in the tool above updates live as you type, so you can watch this process play out for any number. The same idea, expressed algebraically, is bₖ = ⌊n ÷ 2ᵏ⌋ mod 2 — the k-th binary bit is the k-th binary digit of the number when the number is written in base 2 (RapidTables).
Alternative method: powers of 2 (subtraction)
An equally valid approach is the subtraction method, which works directly with the powers of 2 shown in the bit-grid visualizer:
- List the powers of 2 that are ≤ your decimal number: 1, 2, 4, 8, 16, 32, 64, 128 …
- Starting from the largest, subtract it from the number if possible; record a 1. Otherwise record a 0.
- Repeat with the remainder and the next smaller power of 2 until you reach 0.
For 13: the largest power of 2 ≤ 13 is 8 → subtract → remainder 5, record 1. Next is 4 → subtract → remainder 1, record 1. Next is 2 → too big, record 0. Next is 1 → subtract → remainder 0, record 1. Result: 1101. This method is often faster mentally for small numbers and is exactly what the interactive bit grid does when you click bits (Teleport).
Converting negative numbers: two's complement
Computers store negative numbers using two's complement, the near-universal representation for signed integers on modern CPUs (Wikipedia). The process for a chosen bit width is:
- Convert the absolute value to binary and pad with zeros to fill the bit width.
- Invert every bit (0 → 1, 1 → 0). This is the one's complement.
- Add 1. The result is the two's complement representation of the negative value.
Convert −5 to 8-bit two's complement
──────────────────────────────────
Step 1 |5| → 00000101
Step 2 invert → 11111010
Step 3 add 1 → 11111011 Read as unsigned: 251
Read as signed 8-bit: −5
Because the same bit pattern can mean different things depending on how many bits the system uses, bit width is critical. The signed ranges below are the reason C uses int8_t, int16_t, int32_t and int64_t to make width explicit:
| Width | Signed range | Unsigned range |
|---|---|---|
| 8-bit | −128 to 127 | 0 to 255 |
| 16-bit | −32,768 to 32,767 | 0 to 65,535 |
| 32-bit | −2,147,483,648 to 2,147,483,647 | 0 to 4,294,967,295 |
| 64-bit | −9.22 × 10¹⁸ to 9.22 × 10¹⁸ | 0 to 1.84 × 10¹⁹ |
Asymmetry gotcha: An 8-bit signed integer runs from −128 to 127, not −128 to 128 — the extra negative value exists because zero occupies one of the "positive" slots. This is why
abs(INT_MIN) overflows in C.Converting decimal fractions to binary
Fractional parts use the opposite algorithm — repeated multiplication by 2. Multiply the fractional part by 2 and record the integer digit that appears (0 or 1); then take the new fractional part and repeat until it reaches 0 or you hit your desired precision:
Convert 0.625 to binary
───────────────────────
0.625 × 2 = 1.25 → bit 1
0.25 × 2 = 0.5 → bit 2
0.5 × 2 = 1.0 → bit 3 (done — remainder is 0) Result: 0.101₂
Fractions like 0.625 that terminate cleanly are called dyadic: their denominator is a power of 2. But most everyday decimals are not dyadic. 0.1 in binary is 0.0001100110011… repeating forever, because 10 (the denominator of 1⁄10) is not a power of 2. This is the root cause of the famous "0.1 + 0.2 ≠ 0.3" bug seen in JavaScript, Python and every other IEEE 754 language (ExploringBinary). Use the Fraction bits selector in the tool to control how many bits of precision to display for infinite fractions.
IEEE 754 — how real numbers actually live inside a computer
Fixed-point binary works for pure fractions, but computers need a way to store numbers of vastly different magnitudes — 0.000001 and 1,000,000,000 in the same 32 bits. The universal solution is IEEE 754 floating-point, which splits every real number into three parts: a sign bit, a biased exponent, and a mantissa (also called the significand):
| Format | Sign | Exponent | Mantissa | Total | Approx precision |
|---|---|---|---|---|---|
| Single (binary32) | 1 bit | 8 bits | 23 bits | 32 bits | ~7 decimal digits |
| Double (binary64) | 1 bit | 11 bits | 52 bits | 64 bits | ~15–17 decimal digits |
The value is reconstructed as (−1)ˢⁱᵍⁿ × 1.mantissa × 2^(exponent−bias), where the bias is 127 for single precision and 1023 for double precision (GeeksforGeeks). The color-coded IEEE 754 panel in the converter shows the sign, exponent and mantissa segments live for any number you type. JavaScript's Number, Python's float, C's double, Java's double and Rust's f64 are all IEEE 754 double precision.
Decimal to binary in every major programming language
Every mainstream language has a built-in decimal-to-binary conversion. The syntax differs but the result is identical to what this tool produces:
# Python bin(13) # '0b1101' bin(13)[2:] # '1101' format(13, '08b') # '00001101' (8-bit padded) // JavaScript (13).toString(2) // '1101' (13).toString(2).padStart(8, '0') // '00001101' ((-5) >>> 0).toString(2) // '11111111111111111111111111111011' // Java Integer.toBinaryString(13); // "1101" Integer.toBinaryString(-5); // "11111111111111111111111111111011" // C printf("%d\n", 13); // '13' (no %b in std C99) // C23 adds %b: printf("%b\n", 13); → "1101" // Go strconv.FormatInt(13, 2) // "1101" fmt.Sprintf("%b", 13) // "1101" // Rust format!("{:b}", 13) // "1101" format!("{:08b}", 13) // "00001101"
All of these produce unsigned binary for the magnitude. For a fixed-width two's complement view of a negative number, mask with the desired width (e.g. n & 0xFF for 8-bit) before formatting.
Decimal, binary, hex & octal conversion table (0 – 32)
The go-to reference table for the first 32 non-negative integers, plus common power-of-2 milestones. Highlighted rows are the powers of 2:
| Decimal | Binary | Hex | Octal |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 1 | 1 | 1 | 1 |
| 2 | 10 | 2 | 2 |
| 3 | 11 | 3 | 3 |
| 4 | 100 | 4 | 4 |
| 5 | 101 | 5 | 5 |
| 6 | 110 | 6 | 6 |
| 7 | 111 | 7 | 7 |
| 8 | 1000 | 8 | 10 |
| 9 | 1001 | 9 | 11 |
| 10 | 1010 | A | 12 |
| 11 | 1011 | B | 13 |
| 12 | 1100 | C | 14 |
| 13 | 1101 | D | 15 |
| 14 | 1110 | E | 16 |
| 15 | 1111 | F | 17 |
| 16 | 10000 | 10 | 20 |
| 17 | 10001 | 11 | 21 |
| 18 | 10010 | 12 | 22 |
| 19 | 10011 | 13 | 23 |
| 20 | 10100 | 14 | 24 |
| 24 | 11000 | 18 | 30 |
| 31 | 11111 | 1F | 37 |
| 32 | 100000 | 20 | 40 |
| 64 | 1000000 | 40 | 100 |
| 100 | 1100100 | 64 | 144 |
| 128 | 10000000 | 80 | 200 |
| 200 | 11001000 | C8 | 310 |
| 255 | 11111111 | FF | 377 |
| 256 | 100000000 | 100 | 400 |
| 512 | 1000000000 | 200 | 1000 |
| 1024 | 10000000000 | 400 | 2000 |
| 65,535 | 1111111111111111 | FFFF | 177777 |
Powers of 2 reference
Every binary bit is a power of 2 — memorizing the first dozen is a lifetime cheat code for developers, network engineers, and anyone doing capacity planning:
| n | 2ⁿ | Common meaning |
|---|---|---|
| 0 | 1 | |
| 1 | 2 | |
| 3 | 8 | byte (8 bits) |
| 7 | 128 | |
| 8 | 256 | values in a byte |
| 10 | 1,024 | kilo (KiB) |
| 16 | 65,536 | 16-bit unsigned max + 1 |
| 20 | 1,048,576 | mega (MiB) |
| 30 | 1,073,741,824 | giga (GiB) |
| 32 | 4,294,967,296 | 32-bit unsigned max + 1 (IPv4 space) |
| 40 | ~1.1 × 10¹² | tera (TiB) |
| 64 | ~1.8 × 10¹⁹ | 64-bit unsigned max + 1 |
Where developers use decimal ⇄ binary every day
- Networking & subnetting. IPv4 addresses like
192.168.1.1live as 32-bit binary; subnet masks work bit-by-bit. - Bit flags and permissions. Unix file modes (chmod 755), feature flags, and enum bitfields pack many booleans into a single integer.
- Low-level programming. Embedded firmware, drivers, and OS kernels manipulate hardware registers bit by bit.
- Cryptography. XOR, bit shifts, and modular arithmetic on binary values underlie every cipher.
- Data compression & encoding. Huffman codes, Base64, UTF-8 all operate on binary patterns.
- Debugging floating-point bugs. Understanding IEEE 754 binary is the fastest way to explain "why doesn't 0.1 + 0.2 equal 0.3?"
- Graphics & games. Color values (RGBA), texture packing, and depth buffers are binary-native.
A quick history of binary
The binary system was formally described by the German polymath Gottfried Wilhelm Leibniz in his 1703 manuscript Explication de l'Arithmétique Binaire, though the idea has independent roots as far back as the ancient Chinese I Ching and the work of Thomas Harriot in the late 1500s (Wikipedia, ACM). Leibniz also invented hexadecimal and dreamed of a mechanical calculator that would work in binary — an idea only realized centuries later.
Binary became the language of computing in the 1930s and 1940s. Claude Shannon's 1937 master's thesis proved that Boolean algebra — a branch of logic developed by George Boole in the 1850s — could be implemented with electrical relays, giving engineers the mathematical toolkit to build digital circuits. Every microprocessor since ENIAC has been, at heart, a very fast machine for adding, subtracting, and comparing binary numbers.
Frequently asked questions
How do I convert a decimal number to binary?
Divide the decimal number by 2, record the remainder (0 or 1), replace the number with the quotient, and repeat. When the quotient hits 0, read the remainders from bottom to top. Decimal 13 gives remainders 1, 0, 1, 1 → read up → 1101.
What is 10 in binary?
Decimal 10 = 1010 in binary, A in hex, 12 in octal. It equals 8 + 2, so bits 3 and 1 are set.
What is 255 in binary?
Decimal 255 = 11111111 in binary — eight ones. It's the largest value in an 8-bit unsigned integer and equals FF in hex.
How do you convert a negative decimal number to binary?
Use two's complement: convert the absolute value, pad to your bit width, invert every bit, then add 1. In 8-bit, −5 becomes 11111011.
What is the range of an 8-bit, 16-bit, 32-bit and 64-bit signed integer?
8-bit: −128 to 127. 16-bit: −32,768 to 32,767. 32-bit: −2,147,483,648 to 2,147,483,647. 64-bit: −9.22 × 10¹⁸ to 9.22 × 10¹⁸.
How do you convert a decimal fraction to binary?
Multiply the fractional part by 2, record the integer digit (0 or 1), repeat with the new fractional part until it reaches 0 or you hit your desired precision.
Why is 0.1 in binary a repeating fraction?
0.1 in decimal has no exact binary representation because 10 is not a power of 2. In binary it becomes 0.0001100110011… repeating forever. This is why 0.1 + 0.2 does not exactly equal 0.3 in IEEE 754 arithmetic.
How does IEEE 754 store decimal numbers in binary?
IEEE 754 uses a sign bit, a biased exponent, and a mantissa. Single precision is 1 + 8 + 23 bits (32 total, ~7 decimal digits). Double precision is 1 + 11 + 52 bits (64 total, ~15–17 decimal digits).
How do I convert decimal to binary in Python?
Use the built-in bin(13) which returns '0b1101'. Use bin(13)[2:] or format(13, 'b') to drop the prefix, or format(13, '08b') for zero-padded 8-bit output.
How do I convert decimal to binary in JavaScript?
Call (13).toString(2), which returns the string '1101'. For a fixed 8-bit width, use (13).toString(2).padStart(8, '0'). For a negative number as unsigned 32-bit, use ((-5) >>> 0).toString(2).
Sources & methodology
- RapidTables — Decimal to Binary Conversion — rapidtables.com
- Wikipedia — Two's complement — wikipedia.org
- GeeksforGeeks — IEEE Standard 754 Floating-Point Numbers — geeksforgeeks.org
- ExploringBinary — Arbitrary-precision decimal/binary converter — exploringbinary.com
- Teleport — Decimal-to-Binary Converter guide — goteleport.com
- MDN — Number.prototype.toString — developer.mozilla.org
Integer conversion uses JavaScript's native BigInt for arbitrary precision. Two's complement is computed as (~n + 1) & mask for the selected bit width. Fractional conversion uses repeated multiplication by 2, truncated at the chosen precision (an ellipsis "…" marks non-dyadic infinite expansions). IEEE 754 bits come from DataView.setFloat32 / setFloat64.