Lab1: Lecture 2, 3, 4 (CS:APP Chapter 2)
Summing Unsigned: w bits -> sum to w+1 bits
Unsigned: w bits -> 2w bits
Signed: w bits -> 2w bits
Multiplication: discard bits
Power of 2 Multiplication:
Power of 2 Division:
u >> k = roundDown(u / 2^k)
(x + (0x01 << k) - 1) >> k = roundZero(x / 2 ^k)
-x = ~x + 1 (we plus 1 because ~x + x = -1)
Big Endian: Sun (Oracle SPARC), PPC Mac, Internet
Little Endian: x86, ARM with Android, iOS, Linux
Below code truncate a number in little endian
*(short *)(&x)
Exception: strings
Table of Content