−1 at 8, 16 and 32 bits — two's complement

exam standardall ones at every width

Answer

11111111 / 1111111111111111 / 11111111111111111111111111111111

Why this example is worth doing

Minus one is all ones regardless of width, which is the most useful single fact about the representation and the reason ~0 is the idiomatic all-bits-set constant. The page shows it at three widths to make the width-independence visible, and connects it to the bitwise NOT example on the NOT gate page, where the same pattern arrives from the logic side.

Try your own input in the Two’s complement. Encode and decode signed binary at any width, with overflow and sign extension.

How the answer is reached

-1 in 8-bit two's complement

Encode -1 in 8-bit two's complement. Representable range: -128 to 127.

|-1| in binary00000001

invert every bit11111110

add 111111111invert-and-add-one is the negation rule

8-bit pattern1111 11110xFF

check11111111 reads 255 unsigned and -1 signed

-1 in 16-bit two's complement

Encode -1 in 16-bit two's complement. Representable range: -32768 to 32767.

|-1| in binary0000000000000001

invert every bit1111111111111110

add 11111111111111111invert-and-add-one is the negation rule

16-bit pattern1111 1111 1111 11110xFFFF

check1111111111111111 reads 65535 unsigned and -1 signed

-1 in 32-bit two's complement

Encode -1 in 32-bit two's complement. Representable range: -2147483648 to 2147483647.

|-1| in binary00000000000000000000000000000001

invert every bit11111111111111111111111111111110

add 111111111111111111111111111111111invert-and-add-one is the negation rule

32-bit pattern1111 1111 1111 1111 1111 1111 1111 11110xFFFFFFFF

check11111111111111111111111111111111 reads 4294967295 unsigned and -1 signed

Compare with

Open the Two’s complement

This input is entered in the tool itself — it is too rich for a link to carry.

Note:

Notation this page assumes

  • Bit strings are written most significant bit first, and bit 0 is the least significant bit.
  • A width is stated explicitly wherever it changes the answer; nothing is silently sign-extended or truncated.
  • Negative values are two’s complement, not sign–magnitude, and the most significant bit is the sign bit.

Sources

  • Knuth, The Art of Computer Programming, Vol. 2, §4.1 “Positional Number Systems” (1997)
  • IEEE 754-2019, Standard for Floating-Point Arithmetic