liveBook · Manning

Two's complement

As explained in Quantization and Fast Inference

Two's complement representation encodes signed integers so that the highest-order bit contributes a negative power-of-two weight.

Two's complement lets hardware represent signed integers in binary. The most significant bit contributes a negative place value; for an 8-bit integer, it contributes −128, while the remaining bits contribute +64 through +1. section 2.1

Decoding 1111 1111

For an 8-bit signed integer, add the bit values: −128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = −1. In Q3.4 format, the scale is 1/16, so this pattern represents −1/16, or −0.0625. section 2.1

Figure 2.2 The 8-bit signed integer ring. The 256 possible bit patterns wrap around a circle, with 0 at the top and −1 (1111 1111) one step below it. Moving clockwise increments the integer; moving counterclockwise decrements it.

The 8-bit ring visualizes wraparound: decrementing zero produces 1111 1111, the representation of −1. section 2.1

How Quantization and Fast Inference covers it

How deep it goes
Works through bit weights and wraparound using an 8-bit example and an odometer analogy.
Examples
Uses the 1111 1111 pattern, an 8-bit register, and an odometer analogy.
What you can do after
Understand how to decode signed fixed-point bit patterns by summing their weighted bit values and applying the scale.
How it connects
Connects two's complement to fixed-point arithmetic and Q-format scaling.

Also explained in

Compare how 6 books explain two's complement →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Quantization and Fast Inference. The section links point to the parts of the book it draws on.