Learn the method
x << 38-bit word · arithmetic wraps modulo 256| Operator | Bits 7 → 0 | Decimal |
|---|---|---|
x | 1001 10012 | 153 |
Result | 1100 10002 | 200 |
Multiplication by 2^3, modulo 256, gives 11001000 (200). This is a fixed-width word operation.
#include <stdint.h>
uint8_t x = 153;
uint8_t result = (uint8_t)((unsigned)x << 3);C17 · snippets use uint8_t from <stdint.h>. Casts keep the low 8 bits; shifts use unsigned operands. Run the statements inside a function.
CS:APP · §2.1.10, §2.3.7