Learn the method
x ^ y8-bit word · arithmetic wraps modulo 256| Operator | Bits 7 → 0 | Decimal |
|---|---|---|
x | 1001 10012 | 153 |
y | 1000 11112 | 143 |
Result | 0001 01102 | 22 |
Only differing positions remain set: 00010110 (22). Unlike OR, 1 XOR 1 is 0.
#include <stdint.h>
uint8_t x = 153;
uint8_t y = 143;
uint8_t result = x ^ y;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.8