logo CodeStepByStep logo

bitmask0

Author: Julie Zelenski (on 2018/02/03)

A bit vector is an unsigned value treated as a set of independent boolean values. The bit at a given position represents a particular member and if that bit is on in the bit vector, the set contains that member. Changing a particular bit allows you to add or remove a member from the set. When operating on a bit vector, you apply a bitwise operator with a mask to isolate the bits of interest.

Do you know how to perform operations on a bit vector? Test yourself with the expressions below. Assume mine and yours are unsigned ints. The terms "low" and "high" refer to "less significant" and "more significant", i.e. the lowest bit is the least significant. (You will also see "rightmost" and "leftmost" used as synonyms for most and least significant.)

test if mine has lowest bit on
(order shuffled)
set lowest bit in yours
(order shuffled)
clear lowest bit in yours
(order shuffled)
toggle lowest bit in yours
(order shuffled)
union mine with yours
(order shuffled)
intersect mine with yours
(order shuffled)
remove yours from mine
(order shuffled)
is yours a subset of mine?
(order shuffled)

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.