Encoding desk

Decimal to Binary

Convert a signed decimal integer to binary without floating-point rounding.

Decimal to Binary: Express a whole decimal number using only binary digits. Decimal to Binary produces the shortest base-2 magnitude, retaining a minus sign for negative input. Use it to see which bit weights make up a flag value or to prepare a binary answer before adding any required field padding. Runs 100% locally in your browser with zero server file uploads.

Runs
In your browser
Cost
Free · no sign-up
Availability
Ready to use
Decimal → Binary / local workbenchLocal processing

Runs entirely in your browser

256 character input · 1,024 character output

Result

Ready

Conversions run locally. Numeric values are integers, signs are normalized, and prefixes such as 0b or 0o are intentionally not accepted.

Division rule and a worked conversion

Starting with non-negative magnitude q, calculate q_next = floor(q / 2) and remainder r = q − 2×q_next. Repeat until q becomes zero, then read the remainders backwards. For input 45: 45 = 2×22 + 1; 22 = 2×11 + 0; 11 = 2×5 + 1; 5 = 2×2 + 1; 2 = 2×1 + 0; 1 = 2×0 + 1. Reversing 1,0,1,1,0,1 gives 101101. Checking the set weights gives 32 + 8 + 4 + 1 = 45.

Exact output, encoding choices

The decimal field accepts at most 256 characters, including a sign; binary output is capped at 1,024 characters. Decimal fractions and scientific notation are rejected. Larger-than-64-bit integers are allowed within those text limits, with no silent wraparound or rounding. JavaScript Number only guarantees consecutive integers through 9,007,199,254,740,991 (https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-number.max_safe_integer); this converter avoids that limit by keeping the calculation exact. The Sonoma State text (https://bob.cs.sonoma.edu/IntroCompOrg-RPi/sec-codes.html) explains BCD as a different encoding. Neither byte order nor BCD is selected automatically.

How to use it

  1. Enter the value in the format shown below.
  2. Run the conversion and check the result against your source convention.
  3. Copy or download the output in the form required by your destination.

Privacy & limitations

Conversion runs in your browser. Your values and results are not uploaded.

Related tools

Frequently asked questions

Why does −5 appear as −101 instead of 11111011?

The result is a signed mathematical numeral, not a fixed-width memory pattern. To prepare an eight-bit two’s-complement representation manually, check that −5 fits, add 256 to get 251, then convert 251 and obtain 11111011. The chosen width belongs to the receiving format.

Can I request eight bits or prevent field overflow?

There is no width or padding option. Add leading zeros yourself for a positive value that fits. Unsigned w-bit fields accept 0 through 2^w − 1; signed two’s-complement fields accept −2^(w−1) through 2^(w−1) − 1. A successful conversion alone does not check those bounds.

Does this make binary-coded decimal?

No. Ordinary binary encodes the entire magnitude. For decimal 42 the result is 101010, whereas 8421 BCD represents the decimal digits 4 and 2 separately as 0100 0010. A device expecting BCD will misinterpret the ordinary binary output. Check the protocol before copying it.

Free tool · runs in your browser · no account required