Objective
An integer can act as a set of flags: bit i is 1 if flag i is on. With |=, &= ~ and ^= you change a flag, and with (m >> i) & 1 you query it.
Instructions
- The mask starts at 0. The first line has the number
nof commands:set i(turns the bit on),clear i(turns it off),toggle i(flips it),test i(shows 0 or 1) orshow(shows the integer value of the mask).
5
set 0
set 3
test 3
toggle 0
show
1
8
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise