Binary Converter

By: Calculator Grid

Binary Converter

Convert signed integers between decimal and fixed-width binary, including magnitude, one's complement, and two's complement representations.

8-bit – 128 to 127Signed two's complement
Example workbook ready.

Inputs

Sets the signed range and the exact output width.
Enter a whole base-10 number within the selected signed range.
Enter up to the selected number of bits. The leading bit is interpreted as the sign bit when the full width is used.

Live results

Two's complement binary
1010 1001
Decimal value
– 87
Positive magnitude
0101 0111
One's complement
1010 1000
Unsigned value
169
– 87 equals 10101001 in 8-bit two's complement.

Bit-position breakdown

Bit position Bit Unsigned weight Unsigned contribution
For a full-width signed value, the most-significant bit contributes a negative weight in two's-complement interpretation; the table keeps unsigned weights visible so the stored bit pattern is easy to audit.

How to use the Binary Converter

What this calculator does. This converter translates whole integers between ordinary decimal notation and a fixed-width binary representation. It also separates the three representations that matter when the decimal number is negative: the binary magnitude of the positive opposite, its one's complement, and the final two's-complement bit pattern used by most modern computers. The tool is an exact integer converter; it does not handle fractions, floating-point encodings, text characters, or arbitrary-precision values beyond 64 signed bits.

When to use it. It is useful when checking a programming exercise, interpreting a register or byte dump, learning signed integer storage, or verifying the bit pattern that should be written to a device. It also helps compare what the same bits mean as an unsigned number and as a signed two's-complement number.

How to calculate. The calculator opens with a complete 8-bit example for decimal – 87, so the results and the Excel workbook are immediately available. Follow these steps:

  1. Choose Binary number representation. The selected width determines the signed decimal range and pads every output to exactly that many bits.
  2. Replace the value in Decimal to convert base 10 to binary, or replace Binary to convert a bit pattern back to decimal. Editing either field makes it the active source and updates the other field automatically.
  3. Read Two's complement binary as the stored signed pattern. Compare it with Positive magnitude, One's complement, Decimal value, and Unsigned value.
  4. Use the bit-position table to audit each bit and its power-of-two contribution. Select Download Excel to export the current controls, outputs, and bit rows. Reset clears the demonstration data and may disable export until you enter a complete valid value again.

Input guide. Binary number representation is required and accepts 4, 8, 12, 16, 32, or 64 bits. For example, 8-bit signed integers range from – 128 through 127. Increasing the width preserves the numerical value while adding leading sign-extension bits. A common mistake is choosing too few bits for the desired decimal value. Decimal is a required whole base-10 integer when used as the source; signs are accepted, but grouping commas, decimals, and scientific notation are rejected. An example is – 87. A value outside the displayed range is invalid. Binary is a required string of zeroes and ones when used as the source. It may contain spaces for readability, but no prefixes such as 0b. Up to the selected width is accepted; shorter values are treated as positive and left-padded with zeroes, while a full-width leading 1 is interpreted as negative two's complement.

Output guide. Two's complement binary is the exact fixed-width signed bit pattern. Decimal value is its signed base-10 interpretation. Positive magnitude is the selected-width binary form of the absolute value. One's complement flips every magnitude bit for a negative input; for a nonnegative input it matches the ordinary binary pattern. Unsigned value interprets the stored bits without a sign, so it can be much larger than the signed value when the leading bit is 1. The summary pills show width, signed range, and interpretation mode. In the table, Bit position counts from the least-significant bit at zero, Bit is the stored digit, Unsigned weight is 2 raised to that position, and Unsigned contribution is the weight when the bit is 1 or zero otherwise.

Worked example. With 8 bits and decimal – 87, the positive magnitude is 87 = 0101 0111. Flipping every bit gives the one's complement 1010 1000. Adding one gives the two's-complement pattern 1010 1001. Interpreted unsigned, that pattern equals 169; interpreted as signed 8-bit two's complement, it equals 169 – 256 = – 87. This matches the first-open results and workbook.

Learn more. The University of California, Riverside provides a concise guide to binary, octal, hexadecimal, and decimal conversion. For the broader theory of positional notation, see the Wolfram MathWorld overview of positional number systems.

How the conversion works

For a nonnegative integer, repeated division by two produces binary digits from right to left: each remainder is either 0 or 1. The reverse conversion uses positional weights. If the bits are bₙ...b₁b₀, the unsigned value is the sum of each bit multiplied by 2 raised to its position.

Unsigned value = b₀×2⁰ + b₁×2¹ + ... + bₙ×2ⁿ

Two's complement makes addition and subtraction work with the same hardware for positive and negative integers. For an N-bit negative value, the stored unsigned pattern equals 2ᴺ plus the negative decimal value. Equivalently, write the positive magnitude in N bits, invert all bits, and add one. The signed range is – 2ᴺ⁻¹ through 2ᴺ⁻¹ – 1. The Cornell two's-complement notes explain why the leading bit carries negative weight in the signed interpretation.

Practical interpretation and common mistakes

Width is part of the number. The pattern 1001 is – 7 as a signed 4-bit number, but 9 as an unsigned number. The same visible digits padded to eight bits as 0000 1001 represent positive 9. When converting a negative value to a wider signed type, sign extension repeats the leading 1; simply adding zeroes on the left changes the value. Also distinguish the one's complement intermediate from the final two's complement: the final add-one step is essential.

For software work, verify the language's integer width and signedness rather than assuming they match the calculator. The C standard's integer model and implementation-defined widths are discussed in the C arithmetic types reference. This calculator provides the mathematical bit pattern, not a guarantee about a particular compiler, protocol, or hardware register.