1011 0101 read as a signed 8-bit value — two's complement

introthe leading 1 means negative

Answer

-75

Why this example is worth doing

Decoding rather than encoding. The top bit is 1 so the value is negative, and the magnitude comes from inverting and adding one — the same operation, which is its own inverse. The page also gives the direct method of treating the top bit as having weight −128 and summing normally, since that route generalises better and makes the next example obvious.

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

Decode 10110101 as 8-bit two's complement

bit string1011 01010xB5

unsigned reading181straight positional value of the bits

sign bit1set, so the value is negative

181 - 2^8-75

Compare with

Open this example in the Two’s complement

The field arrives filled in with this example’s input.

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