01010101010101011~52-5 & 0xFF3bin(251)4256 & 0xFF5251 - 25601010112801640132011601801421carry0
Bit lamps: a lit lamp is a 1, a dark lamp a 0Tags: each bit's place value (the top one is −128)Sum and carry cells: column addition, right to leftCalculator: the byte read as a signed decimal numberThree rows of eight bits share one ones column. Back: 5 as 00000101. Middle: the signed byte, with each place value on a tag in front; the top place is worth −128. Tokens hop along dashed trails: each bit of 5 flips down into the middle row (11111010), +1 lands in the ones bit (11111011 = −5), each place weight adds into the calculator, and a carry ripples left through the sum row until the ninth bit falls off. −128 has no positive partner in 8 bits: flipping 10000000 gives 01111111, and adding 1 gives 10000000 again.

Signed bytes

  1. A byte is 8 bits, so it has 2 to the power 8 = 256 patterns. Read as plain binary, they mean 0 to 255. The back row holds 5: 00000101, which is the 4 bit plus the 1 bit.

Negating 5

Adding

Range and code

Try it in the Python prompt

;; step 1/10 · A byte holds 256 patterns
>>> 2**8                  # patterns in one byte
256
>>> 0b00000101
5

Why flip and add one works: x plus its flipped copy is always 11111111, which is −1. So the flip equals −x − 1, and adding 1 gives −x. Python defines ~x the same way, as −(x + 1). The name: as plain binary, −x is stored as 2^8 − x, its complement with respect to 2^8 = 256. For 5 that is 256 − 5 = 251 = 11111011.