CHAPTER 30. SIGNED NUMBER REPRESENTATIONS CHAPTER 30. SIGNED NUMBER REPRESENTATIONS
- size_t.
- Signed types have the sign in the most significant bit: 1 mean “minus”, 0 mean “plus”.
- Promoting to a larger data types is simple:24.5 on page 388.
- Negation is simple: just invert all bits and add 1. We can remember that a number of inverse sign is located on the
opposite side at the same proximity from zero. The addition of one is needed because zero is present in the middle. - The addition and subtraction operations work well for both signed and unsigned values. But for multiplication and
division operations, x86 has different instructions:IDIV/IMULfor signed andDIV/MULfor unsigned. - Here are some more instructions that work with signed numbers:CBW/CWD/CWDE/CDQ/CDQE(A.6.3 on page 890),
MOVSX(15.1.1 on page 189),SAR(A.6.3 on page 893).