Reading Two's Complement
Read a signed binary number using the negative weight of its high bit and the positive weights of the other positions.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
In a \(w\)-bit two's-complement field, the high bit carries weight \(-2^{w-1}\).
Read one negative pattern
With four bits, 1101 means \(-8+4+1=-3\). Interpreting the same bits as unsigned gives thirteen. The unsigned range supplies that second interpretation.
Compute the endpoints
The pattern 1000 means minus eight. Combining all lower bits with high bit zero gives seven. The range is asymmetric, which affects taking absolute values at the minimum.[1]
Give the sign bit its negative place value
In a five-bit two's-complement word, the top bit has weight minus sixteen. The pattern 10110 therefore gives \(-16+4+2=-10\). Reading it as unsigned gives twenty-two. Subtracting thirty-two from an unsigned reading with its high bit set is equivalent. See unsigned field ranges.
Pattern signed unsigned
00110 6 6
10110 -10 22
10000 -16 16
11111 -1 31
Keep the width and signed rule with the value
The same glyphs can mean another value after changing the width or treating bytes as unsigned. Test the most negative pattern and the largest nonnegative pattern to confirm the asymmetry. See sign extension.