Every int is 32 bits of 0s and 1s — bitwise operators let you edit those bits directly and in parallel.
1 Numbers are bits
5 is binary 101; 6 is 110. Bitwise operators work on those columns all at once.
2 &, | and ^
AND keeps bits where both are 1; OR where at least one is; XOR where they differ.
3 Shifts move bits
x << n slides bits left (multiplying by 2 each step); x >> n slides them right.
4 Masks test bits
ANDing with a mask like 1 (binary 001) checks whether one specific bit is switched on.
Numbers are bits
Numbers are bits15 is binary 101; 6 is 110. Bitwise operators work on those columns all at once. &, | and ^2AND keeps bits where both are 1; OR where at least one is; XOR where they differ. Shifts move bits3x << n slides bits left (multiplying by 2 each step); x >> n slides them right. Masks test bits4ANDing with a mask like 1 (binary 001) checks whether one specific bit is switched on. 4 building blocks make up Numbers are bits
Press play — a mask checks bit 0 of flags, then a left shift doubles the value in one move.
preprocessThe preprocessor pastes in stdio.h — printf comes from there.
Memory
no variables yet — press play
Console
output appears as the program runs…
Click an operator, then click what it does to lock the pair.
6 conceptsTap a card to expand ?a & bdrops into place
?a | bdrops into place
?a ^ bdrops into place
?a << ndrops into place
?a >> ndrops into place
?~adrops into place
Work column by column in binary before you guess.
Your predicted output — one line per console line
Hint: Write 6 = 110 and 3 = 011, then combine column by column: & = 010, | = 111, ^ = 101.
Build a mask with a shift, AND it in, then let the result decide.
process decision input / output start / end
01Bitwise operators act on every bit of an int in parallel.
02& with a mask tests bits; | with a mask sets them; ^ toggles them.
03x << n multiplies by 2^n; x >> n divides by 2^n for unsigned ints.
04Masks like (1 << n) isolate bit n — the pattern behind flags and permissions.
05Hex (0x) notation and binary thinking go hand in hand with bit tricks.