Solved.tools — Free Online Calculators & Tools

We use cookies for analytics and advertising. Learn more about our cookie policy

Decimal to Binary Converter

Last updated: 17 August 2026

Reviewed by Gavin · Research and drafting assisted by AI

Type a decimal integer or fraction in the left field, or paste a binary string in the right field, and the other updates instantly. The calculator uses the divide-by-2 method for the integer portion and the multiply-by-2 method for any digits after the binary point, so the result agrees with what every introductory CS textbook teaches. Octal and hexadecimal read-outs are included as bonuses and computed with the same primitive that JavaScript uses internally (radix 8 and radix 16 of Number.prototype.toString).

Fractional bits:
Result in binary1010 10
Result in octal (base 8)052
Result in hexadecimal (base 16)0x2A
Also in decimal42
Bits in integer part6 bits
Fractional precision16 bits after the point
Integer path: divide-by-2 remainder method. Fractional path: multiply-by-2 carry method.42 dec → 1010 10 bin
Was this helpful?


Decimal to Binary Converter

The decimal-to-binary converter translates numbers between base 10 (the system every human writes by hand) and base 2 (the system every modern computer stores and processes natively). It is used by computer science students learning how integers and floating-point values are represented in memory, by embedded firmware engineers inspecting bit masks and register layouts, by networking technicians reading IPv4 subnet masks and MAC addresses, by cryptographers and hash designers verifying byte-level output, by electronics hobbyists mapping decimal resistor codes onto shift-register patterns, and by anyone who needs a quick, exact decimal ⇄ binary check without launching a separate REPL.

Binary is everywhere in computing, but writing it down by hand is slow and error-prone once the number gets past four or five digits. A decimal value of 255 takes three keystrokes to type but eight binary digits to write, and one typo turns the answer into nonsense. A live converter that runs in the browser, supports fractions, and gives bonus read-outs in octal and hexadecimal is the fastest way to verify a manual calculation or to convert a long decimal literal once and copy the result.

How to Use the Decimal to Binary Converter

  1. Type a value in either the decimal field or the binary field. The other field updates instantly.
  2. The integer portion is converted using the divide-by-2 remainder method, the same algorithm taught in every introductory computer-architecture textbook.
  3. The fractional portion (digits after the decimal point) is converted using the multiply-by-2 carry method, with the precision controlled by the Fractional bits toggle (8, 16, 24, 32, or 64 bits).
  4. Bonus rows show the matching octal (base 8) and hexadecimal (base 16) representations, plus a count of the bits in the integer part so you can plan register widths and type sizes.
  5. Use the copy buttons to grab any of the read-outs to the clipboard in one click.

Negative numbers round-trip cleanly: typing -5 in either field produces -101 on the other side. The sign character stays attached to the integer portion; the fractional portion is always non-negative.

The Formulas Behind the Conversion

FromToMethod
Decimal integerBinaryDivide by 2, write the remainders in reverse
Decimal integerOctalDivide by 8, write the remainders in reverse
Decimal integerHexDivide by 16, write the remainders in reverse
Decimal fractionBinaryMultiply by 2, write the integer parts in order
BinaryDecimal integerSum 2ⁿ for every set bit
Binary fractionDecimal fractionSum 2⁻ⁿ for every set fractional bit

For an integer n, the divide-by-2 algorithm repeats n = q·2 + r with r ∈ {0,1} until q = 0, then writes the remainders from bottom to top. That sequence of 0s and 1s, read as a string, is the binary representation. The same primitive handles any base: dividing by 8 produces octal, dividing by 16 produces hexadecimal (with remainders 10 through 15 written as a through f).

For a fraction f ∈ (0, 1), the multiply-by-2 algorithm repeatedly doubles f and writes down the integer part of the result. Each iteration contributes one bit after the binary point. Most decimal fractions do not terminate in binary, 0.1 decimal, for instance, repeats forever as 0.0001100110011…, so the calculator rounds to the requested number of bits.

Worked Examples

Example 1, 42 decimal to binary

Divide by 2, recording the remainder each time:

Stepnn ÷ 2Remainder
142210
221101
31050
4521
5210
6101

Read the remainders bottom to top: 42 dec = 101010 bin (six bits). Octal: 52. Hex: 2A.

Example 2, 255 decimal to binary (the byte boundary)

255 ÷ 2 = 127 r 1, 127 ÷ 2 = 63 r 1, 63 ÷ 2 = 31 r 1, 31 ÷ 2 = 15 r 1, 15 ÷ 2 = 7 r 1, 7 ÷ 2 = 3 r 1, 3 ÷ 2 = 1 r 1, 1 ÷ 2 = 0 r 1. Reading bottom-up: 255 dec = 11111111 bin, eight 1 bits, the largest value that fits in one byte. Octal: 377. Hex: FF.

Example 3, 0.625 decimal to binary

Multiply by 2 repeatedly:

Stepff × 2Integer part
10.6251.251
20.250.50
30.51.01

Read the integer parts in order: 0.625 dec = 0.101 bin. Terminates after three bits because 0.625 = 5/8 = 1/2 + 1/8, a sum of two negative powers of 2.

Example 4, 0.1 decimal to binary (the famous repeating fraction)

Multiplying 0.1 by 2 repeatedly produces 0.0001100110011001100110011…. The pattern 0011 repeats forever, so the binary representation is infinite. The converter rounds to 16 bits by default, producing 0.0001100110011001. This is exactly why IEEE 754 float cannot represent 0.1 exactly, the rounding repeats into the storage format.

Example 5, 65535 decimal to binary (the 16-bit boundary)

The largest 16-bit unsigned integer, used everywhere as a port-number maximum, a colour-channel maximum, and a default IPv6 segment maximum, is 65535 dec = 1111111111111111 bin (sixteen 1 bits). Octal: 177777. Hex: FFFF. One more, 65536, flips to a 17-bit value 10000000000000000 and a 5-digit hex 10000.

Example 6, A 32-bit IPv4-style integer

192.168.1.1 as a 32-bit unsigned integer is 3232235777 decimal. In binary that is 11000000101010000000000100000001, in octal 30022500101, in hex 0xC0A80101. Spotting the four octets of the dotted-decimal address becomes trivial when the binary is grouped into four 8-bit chunks.

How the Conversion Is Implemented

The calculator uses Number.prototype.toString(radix) for the integer portion. The JavaScript specification defines this primitive to return the shortest base-r representation of a non-negative integer and to accept a leading - sign for negatives. For values within Number.MAX_SAFE_INTEGER (2⁵³ − 1), this is exact and reproducible across every browser, every Node version, and every platform the calculator runs on. For larger values the calculator falls back to BigInt.prototype.toString(radix) so it keeps working with arbitrarily large inputs without precision loss.

The fractional path is implemented as a pure loop. Each iteration multiplies the running remainder by 2, appends 1 if the new value is at least 1, otherwise appends 0, and subtracts the integer part. The loop runs for as many bits as the precision control allows, then stops. The result is concatenated to the integer string after a literal ..

Octal and hexadecimal read-outs are produced by the same primitive with radix = 8 and radix = 16. They round-trip with parseInt(s, radix) for any base that uses only digits 0 to 9, and the calculator uses the standard 0123456789abcdef digit set so both upper-case and lower-case hex are accepted.

Where Decimal ⇄ Binary Conversions Show Up

Bit flags and masks. C, Rust, Go, and most systems languages let you write 0b101010 for binary literals, but JavaScript, Python, Java, and many older languages do not. To set or clear an individual bit you need the decimal value of the bit position: bit 0 is 1, bit 1 is 2, bit 2 is 4, bit 3 is 8, and so on. The calculator makes this trivial: 8 dec → 1000 bin → 0x8 → 010 (octal).

Subnet masks. IPv4 subnets are usually written in dotted decimal (255.255.255.0), but each octet is an 8-bit unsigned integer. Convert /24 (the prefix length) to a 32-bit mask: 24 ones followed by 8 zeros = 11111111111111111111111100000000 = 0xFFFFFF00 = 4294967040 decimal. The same trick turns a CIDR prefix into a wildcard mask for routing rules.

Byte literals and file sizes. A 256-byte header is 0x100 (hex) or 0400 (octal). Knowing both saves you when reading log lines that mix the two (malloc(0x800) is 2048 bytes, not 8 bytes).

Cryptography and hashing. MD5 produces a 128-bit digest written as 32 hex characters; SHA-1 produces a 160-bit / 40-character hex string; SHA-256 produces a 256-bit / 64-character hex string. Each hex digit is exactly four binary digits, so the digest length in bits is exactly four times the digest length in hex digits.

Floating-point debugging. IEEE 754 binary64 gives 52 explicit mantissa bits plus an implicit leading 1, for 53 bits of precision. That is why the fractional-bits toggle offers 8, 16, 24, 32, and 64, the 52-bit mantissa falls inside that range, and 64 lets you see the full representation when debugging edge cases like 0.1 + 0.2 ≠ 0.3.

Common Mistakes to Avoid

Forgetting the sign when converting negative numbers. The binary representation of -5 is -101, not 11111011 (that would be -5 as an 8-bit two's-complement integer). The calculator always places the sign in front of the magnitude so the output stays portable across signed and unsigned contexts.

Treating leading zeros as significant. 01010 and 1010 are the same number, the leading zero does not change the value. Binary lengths are usually quoted without leading zeros unless a fixed-width field is in play.

Reading octal values that have a leading 0. In C, JavaScript (legacy), and Python 2, an integer literal that starts with 0 is octal: 010 is decimal 8, not decimal 10. The calculator prefixes octal read-outs with 0 and hex read-outs with 0x to avoid this confusion, and the copy buttons copy the digits only so you can paste the result into any language cleanly.

Confusing kilobinary with kilobinary. 1 KiB (kibibyte) = 1024 bytes = 2¹⁰ bytes, not 1000 bytes. The binary prefixes Ki, Mi, Gi, Ti, Pi were adopted by the IEC in 1998 specifically to remove the ambiguity. RAM and disk-image sizes follow the binary convention; disk-drive marketing follows the decimal one.

Expecting binary fractions to terminate. Most decimal fractions do not. 0.1, 0.2, 0.3, 0.4, 0.6, 0.7, 0.8, and 0.9 all produce repeating binary strings. Increase the fractional-bits control to see how long the pattern takes to repeat; for 0.1 the period is exactly four bits (0011) after the initial 0.0001.

Bits and Bytes at a Glance

BitsBytesMax unsigned valueHex digits
4,151
812552
16265,5354
24316,777,2156
3244,294,967,2958
64818,446,744,073,709,551,61516

Memorising the byte boundary (8 bits → 255 → FF) and the 16-bit boundary (65,535 → FFFF) covers the values that show up most often in network, color, and embedded work.

Common Use Cases

Checking homework. A first-year CS problem asks for the binary representation of 173. Hand-calc gives 10101101. Paste 173 into the decimal field, read the binary field, 10101101. Done.

Reading a hex dump. A log line shows 0xCAFEBABE. Decoding that is 11001010111111101011101010111110 (32 bits). The binary view makes the byte boundaries (11001010 11111110 10111010 10111110) obvious and helps when you are correlating the value against bit positions in a protocol header.

Planning a mask. A network admin needs a /20 subnet mask. /20 = 20 leading ones = 11111111111111111111000000000000 = 0xFFFFF000 = 4,294,967,040 decimal. The octal read-out is even shorter: 37777777000.

Verifying byte order. 0x1234 on a little-endian system is stored as bytes 0x34 0x12. The binary view confirms that the high bit of the first byte is 0 and the high bit of the second byte is 1, which is exactly what the byte-swap convention demands.

Frequently Asked Questions

How do I convert a decimal integer to binary by hand? Use the divide-by-2 method. Repeatedly divide the number by 2, recording the remainder (0 or 1) each time, until the quotient reaches 0. Then write the remainders from bottom to top. For example, 42 ÷ 2 = 21 r 0, 21 ÷ 2 = 10 r 1, 10 ÷ 2 = 5 r 0, 5 ÷ 2 = 2 r 1, 2 ÷ 2 = 1 r 0, 1 ÷ 2 = 0 r 1, read bottom-up gives 101010, which matches the calculator's output.

How do I convert a decimal fraction to binary? Use the multiply-by-2 method. Repeatedly multiply the fractional part by 2, recording the integer part (0 or 1) each time, and using the new fractional part for the next step. The integer parts, written in order, form the digits after the binary point. For example, 0.625 × 2 = 1.25 → write 1, 0.25 × 2 = 0.5 → write 0, 0.5 × 2 = 1.0 → write 1. Result: 0.101.

Why does 0.1 in decimal become a repeating binary fraction? Because 0.1 = 1/10 is not a rational with a denominator that is a power of 2. Binary fractions terminate exactly when the denominator (after simplification) is a power of 2, and 10 = 2 × 5 contains a factor of 5 that cannot be cancelled. The repeating pattern 0011 corresponds to the fraction 1/10 written with denominator 16, 16², 16³, and so on; as the precision increases the repeating tail reveals itself again and again. This is also why 0.1 + 0.2 === 0.3 is famously false in JavaScript.

What is the largest integer this calculator can convert exactly? For the built-in Number path the safe upper bound is 2⁵³ − 1 = 9,007,199,254,740,991, which is the largest integer JavaScript can represent without losing the bottom digit. Beyond that the calculator automatically switches to BigInt, which is only limited by available memory, values with hundreds of decimal digits convert without issue.

How does binary differ from octal and hexadecimal? All three are positional numeral systems with different bases: binary is base 2 (two digits, 0 and 1), octal is base 8 (eight digits 0 to 7), hexadecimal is base 16 (sixteen digits 0 to 9 plus a-f). One octal digit is exactly three binary digits, and one hex digit is exactly four binary digits. This makes octal and hexadecimal convenient shorthand for binary, which is why you see hex everywhere in low-level programming and octal in older Unix file permissions (chmod 755).

Can I convert negative numbers? Yes. Type -42 in the decimal field and the converter produces -101010 in the binary field, -52 in octal, and -2A in hex. The sign character is attached to the magnitude so the result is portable across signed-integer, two's-complement, and sign-magnitude contexts. If you need a fixed-width two's-complement representation (for example, an 8-bit signed byte), read the bits in groups and apply the standard two's-complement rule: invert the magnitude bits and add one.

What does the fractional-bits control change? It sets how many digits after the binary point the converter shows for decimal fractions. The default of 16 matches the IEEE 754 binary64 mantissa width; 8 is enough for graphics work, 24 and 32 are useful for debugging higher-precision integer scaling, and 64 reveals the full binary expansion of values that would otherwise round invisibly. Increasing the precision does not change the value of the binary integer portion, only the trailing bits after the point.


Also try these free tools: