Binary Converter

Convert a decimal number to binary and a binary number back to decimal.

Supports 4–64-bit signed representations with two's complement for negative values.

Updated August 11, 2026
Frank Zhao - Creator
CreatorFrank Zhao
Loading calculator…

Introduction / overview

Binary Converter translates a decimal integer into its fixed-width binary pattern and back again. You pick the representation — 4, 8, 12, 16, 32, or 64 bits, or a custom size — and the tool produces the exact bit pattern, including the part people usually stumble on: how negative numbers are stored.

The two directions are separate converters that share the bit-width setting. Type a decimal in “Decimal to binary” and read the padded pattern below it; type a binary string in “Binary to decimal” and read its decimal value below that.

It is the tool to reach for when you need to know exactly how a value such as 87-87 fits into eight bits — whether you are studying number systems, checking a bit pattern in a microcontroller register, decoding a value from a file format, or working out octets for IP addresses. Because every conversion is exact, the pattern you see is the pattern a real nn-bit register would hold.

How to use / quick start

1

Choose the bit width

Pick a preset such as 8-bit or 16-bit from Binary number representation. For a size that is not listed, choose Other and type the number of bits (anywhere from 2 to 70).

2

Convert decimal to binary

In Decimal to binary, type a whole decimal number. The result below shows the pattern padded to the full width, with the caption telling you the representation (for example, “Number in 8-bit representation.”).

3

Convert binary to decimal

In Binary to decimal, type a string of 0s and 1s — leading zeros are optional. Positive values give a single Decimal result. When the leftmost bit is 1 the value is negative, so the calculator shows both the 1’s complement and 2’s complement readings of that same pattern.

Example 1 — convert 3 to 8-bit binary

Type 33 in the Decimal field. The calculator expands it by place value, then pads the two-bit result out to the full width:

3103_{10}==121+1201\cdot 2^1 + 1\cdot 2^0==11211_2  \ \to\ 0000 00110000\ 0011

So the Binary result reads 0000 0011, and the caption confirms it is an 8-bit representation.

Example 2 — a negative value, −87 in 8 bits

Type 87-87 in the Decimal field. Because the value is negative, the tool encodes it with two’s complement: take the pattern for 8787, flip every bit, then add 1.

8710=0101 0111287_{10} = 0101\ 0111_2 flip \ \xrightarrow{\text{flip}}\ 1010 10001010\ 1000 +1 \ \xrightarrow{+1}\ 1010 10011010\ 1001

The Binary result shows 1010 1001. As an unsigned number that pattern equals 169169; as a signed two’s-complement value it equals 169256=87169 - 256 = -87.

Calculation method

Every bit in the pattern carries a power of two. For nn bits, the leftmost bit is position n1n-1 and the rightmost is position 0:

B=i=0n1bi2iB = \sum_{i=0}^{n-1} b_i \cdot 2^i

Decimal to binary (two’s complement)

B=NB = N for N0\ \text{for } N \ge 0\qquad\qquadB=N+2nB = N + 2^n for N<0\ \text{for } N < 0

Binary to decimal (two’s complement)

N=BN = B for B<2n1\ \text{for } B < 2^{n-1}\qquad\qquadN=B2nN = B - 2^n for B2n1\ \text{for } B \ge 2^{n-1}

1’s complement reading of a pattern with a leading 1

N=B(2n1)N = B - \left(2^n - 1\right) for B2n1\ \text{for } B \ge 2^{n-1}

Variables

  • NN — the decimal value you enter or read
  • BB — the unsigned value of the nn-bit pattern
  • nn — the number of bits (2 to 70)
  • bib_i — the bit at position ii (0 or 1)

Where the limits come from

With nn bits you can represent exactly 2n2^n patterns. A signed nn-bit integer therefore runs from 2n1-2^{n-1} up to 2n112^{n-1}-1. A decimal outside that range triggers the “not in the workable range” error, and a binary string whose value reaches 2n2^n needs more than nn bits and is reported as too long.

Frequently asked questions

Why does 1111 1111 (8-bit) show 0 for 1’s complement and −1 for 2’s complement?

Because the pattern equals 255255 as an unsigned number. One’s complement subtracts 255255, giving 255255=0255 - 255 = 0 (the “negative zero” this scheme has). Two’s complement subtracts 256256, giving 255256=1255 - 256 = -1.

Do I have to type the leading zeros?

No. Type 11 and the result pads it to the selected width — for 8-bit you get 0000 0001. The calculator only cares about the value, not how many digits you wrote.

Why do I get “not in the workable range” or “too long”?

“Not in the workable range” means the decimal value does not fit the signed range for the chosen width (for example, 200200 is too large for 8-bit signed, which tops out at 127127). “Too long” means the binary string has more digits than the selected width allows. In both cases, switch to a larger representation such as 16-bit.

Limitations

This calculator works with whole numbers only: the Decimal field accepts integers, and the Binary field accepts only the digits 0 and 1. The bit width is limited to 2–70 bits, and values must fit the signed range of the selected width — a decimal must fall within 2n1-2^{n-1} to 2n112^{n-1}-1, and a binary string must need no more than nn digits. Conversions are exact, so results are never rounded, but they always include the leading zeros needed to fill the chosen width. For fractional numbers, other numeral systems such as octal or hexadecimal, or bases beyond 2, use a dedicated base converter instead.

Binary Converter - Decimal to Binary and Binary to Decimal