SYSTEMS / Learn
Saved on this device>
← Back to goals

I want to…

Check whether both values are nonzero

Trace this example, understand why the operation works, then try it from memory.

1 · Choose a goal → 2 · Learn the method → 3 · Practise → 4 · Spaced review

Learn the method

(x ≠ 0) ∧ (y ≠ 0)8-bit word · arithmetic wraps modulo 256
BIT-BY-BIT WALKTHROUGH
OperatorBits 7 → 0Decimal
x0000 000121
y0000 001123
Result0000 000121

Logical AND asks whether both values are nonzero. The result is 1, not a bitwise combination.

IN CODEC17
#include <stdint.h>
uint8_t x = 1;
uint8_t y = 3;

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.7, §2.1.9

coffee-bytes / Systems LearningCS:APP + Hacker’s Delight