One's Complement Calculator

By: Calculator Grid

One's Complement Calculator

Convert signed decimal integers and binary bit patterns using fixed-width one's complement notation, with a transparent bit-by-bit check and a real Excel workbook export.

8-bit word Range – 127 to 127 Decimal → binary 2 zero patterns

Workbook ready for the current example.

Inputs

Choose the direction, word size, and value. Results update immediately.

Switches which input is active; the other example is retained until Reset.

The leftmost bit is the sign bit. Wider words support larger magnitudes.

Whole numbers only. For 8 bits, the valid one's complement range is – 127 to 127.

Live result

The output uses the same canonical values as the bit table and workbook.

One's complement

1010 1000

This is the 8-bit one's complement representation of – 87.

Signed decimal value

87

Normalized bit pattern

0101 0111

Opposite decimal value

– 87

Unsigned input value

87

Unsigned complement value

168

Set bits: input / complement

5 / 3

One's complement 1010 1000, representing negative 87.

Bit-by-bit breakdown

Each output bit is the inverse of the input bit at the same position.

Bit position Binary weight Input bit Complement bit
7 (sign) 128 0 1
6 64 1 0
5 32 0 1
4 16 1 0
3 8 0 1
2 4 1 0
1 2 1 0
0 1 1 0
For 0101 0111, flipping every bit gives 1010 1000. The two unsigned bit-pattern values sum to 255, which is 2⁸ – 1.

How to use the one's complement calculator

What this calculator does

This calculator converts a signed decimal integer into a fixed-width one's complement bit pattern, or interprets an entered bit pattern as a one's complement signed value. It also shows the bitwise inverse, unsigned interpretations, set-bit counts, and a row-by-row audit of every bit. The tool is exact for the selected 4-, 8-, 16-, or 32-bit word. It does not model modern machine integer storage automatically: most current processors use two's complement, while one's complement is a distinct historical signed-number system with both positive and negative zero.

When to use it

Use it when checking a digital-logic exercise, comparing signed binary representations, decoding a legacy one's complement word, or verifying that every bit was inverted correctly. It is also useful before studying end-around-carry addition, because you can confirm the exact signed representation of each operand. The University of Alaska Fairbanks notes on one's complement representation and end-around carry provide a concise authoritative explanation of the range and the two zero patterns.

How to calculate

  1. The calculator opens with a ready-to-use 8-bit demonstration: decimal 87. Its workbook has already been built and validated, so Download Excel is immediately available.
  2. Choose Conversion mode. Select “Decimal to one's complement” to encode an integer, or “One's complement to decimal” to decode a binary pattern.
  3. Choose Bit width. The width fixes the sign-bit position and range. If an existing value no longer fits after changing width, the calculator shows a validation message rather than truncating data.
  4. Replace the active example in Decimal integer or Binary bit pattern. Results update live. Read the primary complement first, then use the KPI cards and bit table to verify the interpretation.
  5. Select Download Excel to export the current validated model as a real .xlsx workbook. Reset clears both demonstration inputs and calculated content; export is then disabled until a complete valid active value is entered again.

Input guide

Conversion mode is required and accepts one of two choices. “Decimal to one's complement” makes the decimal field authoritative; “One's complement to decimal” makes the binary field authoritative. Switching modes does not reinterpret the inactive field or silently overwrite it. A common mistake is assuming a plain programming-language bitwise NOT result is automatically a one's complement signed value; language operators may impose their own width and usually use two's complement semantics.

Bit width is required and accepts 4, 8, 16, or 32 bits. For an n-bit one's complement word, the signed magnitude limit is 2n – 1 – 1 in either direction. Thus 8 bits supports – 127 through 127, not – 128. A wider setting adds leading sign-compatible space; a narrower setting can make the current value invalid.

Decimal integer is required in decimal mode. Enter an optional leading minus sign followed by base-10 digits, such as 87 or – 70. Fractions, exponent notation, grouping separators, and unit symbols are rejected. Positive numbers use ordinary zero-padded binary; negative numbers are formed by encoding the positive magnitude and reversing every bit. Zero is encoded as positive zero by default.

Binary bit pattern is required in binary mode. Enter one to the selected number of bits using only 0 and 1; spaces and underscores may be used as visual separators, for example 1011 1001. Missing leading bits are padded with zeros. A leading 0 is nonnegative. A leading 1 is negative unless every bit is 1, which is the negative-zero pattern.

Output guide

One's complement is the exact bitwise inverse of the normalized input pattern. Signed decimal value is the interpreted value of the input. Normalized bit pattern is the input padded to the selected width. Opposite decimal value is the signed interpretation of the complemented pattern. Unsigned input value and Unsigned complement value treat the same bits as ordinary nonnegative binary; they always sum to 2n – 1. Set bits: input / complement counts ones in each pattern, and the two counts sum to the word width.

The “8-bit word” pill shows the selected word size, the “Range – 127 to 127” pill shows the valid decimal interval, the “Decimal → binary” pill shows the active direction, and the “2 zero patterns” pill highlights the defining fact that one's complement has +0 and – 0. Each pill updates when its driving control changes. In the table, Bit position identifies the bit index, Binary weight gives its ordinary unsigned weight, Input bit shows the normalized source, and Complement bit shows its inverse.

Worked example

The startup example uses 8 bits and decimal 87. Ordinary binary 87 is 0101 0111 because 87 = 64 + 16 + 4 + 2 + 1. Reverse every bit: 0 becomes 1 and 1 becomes 0, producing 1010 1000. Interpreted as one's complement, that pattern represents – 87. As unsigned numbers, 0101 0111 equals 87 and 1010 1000 equals 168; together they equal 255, or 28 – 1. The input pattern contains five set bits and the complement contains three, so the counts still total the 8-bit width.

How the representation works

In one's complement, nonnegative values are written like ordinary binary with a leading zero. To negate a nonzero value, invert every bit across the fixed word width. This makes negation visually simple, but it creates two zeros: all zeros for +0 and all ones for – 0. It also means arithmetic addition needs an end-around carry when a carry leaves the most significant bit.

complemented unsigned value = (2n – 1) – original unsigned value

The bit inversion itself matches the logical truth table documented for the bitwise NOT operation, but programming-language results must be interpreted with care because JavaScript Number bitwise operators use a fixed 32-bit two's complement representation.

One's complement versus two's complement

Two's complement starts with the same inversion step and then adds one. That extra step removes negative zero and simplifies arithmetic, which is why two's complement dominates modern systems. Cornell's explanation of forming a two's complement negative number is a useful comparison. Do not add one when using this calculator: the displayed primary result is the pure one's complement.

Boundary note: an 8-bit one's complement word represents – 127 through 127. The all-ones pattern is – 0, so there is no distinct – 128 pattern.