In C, a shift operation moves an integer’s bits left or right by the right operand. For unsigned values, left shifting corresponds to multiplying by a power of two; right shifting corresponds to integer division. Bits that leave the representation are discarded. section 5.7.3
Shifting 240
Take A = 240, whose set bits occupy positions 4 through 7. A << 2 produces 960, with bits in positions 6 through 9. A << 9 would require bit 16 for the full result, so the representation retains only positions 13 through 15 and produces 57344. The right operand must be less than the type’s precision. The related operators <<= and >>= combine shifting with assignment. section 5.7.3
Use shifts deliberately when treating unsigned values as bit sets:
- Use << to specify powers of two and construct individual bit masks. section 5.7.3
- Use >> to discard less-significant bits; the discarded portion corresponds to the remainder modulo 1ULL << n. section 5.7.3
- Prefer unsigned types for bit operations because shifts of negative signed values have unclear semantics. section 5.7.5
#define FLOCK_MAGPIE (1U << magpie)
#define FLOCK_RAVEN (1U << raven)
#define FLOCK_JAY (1U << jay)
#define FLOCK_CHOUGH (1U << chough)
#define FLOCK_EMPTY 0U
#define FLOCK_FULL ((1U << corvid_num)-1)
!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":7}],[{\"line\":1,\"ch\":0},{\"line\":1,\"ch\":7}],[{\"line\":2,\"ch\":0},{\"line\":2,\"ch\":7}],[{\"line\":3,\"ch\":0},{\"line\":3,\"ch\":7}],[{\"line\":4,\"ch\":0},{\"line\":4,\"ch\":7}],[{\"line\":5,\"ch\":0},{\"line\":5,\"ch\":7}],[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":7}],[{\"line\":1,\"ch\":0},{\"line\":1,\"ch\":7}],[{\"line\":2,\"ch\":0},{\"line\":2,\"ch\":7}],[{\"line\":3,\"ch\":0},{\"line\":3,\"ch\":7}],[{\"line\":4,\"ch\":0},{\"line\":4,\"ch\":7}],[{\"line\":5,\"ch\":0},{\"line\":5,\"ch\":7}],[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":7}],[{\"line\":1,\"ch\":0},{\"line\":1,\"ch\":7}],[{\"line\":2,\"ch\":0},{\"line\":2,\"ch\":7}],[{\"line\":3,\"ch\":0},{\"line\":3,\"ch\":7}],[{\"line\":4,\"ch\":0},{\"line\":4,\"ch\":7}],[{\"line\":5,\"ch\":0},{\"line\":5,\"ch\":7}],[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":7}],[{\"line\":1,\"ch\":0},{\"line\":1,\"ch\":7}],[{\"line\":2,\"ch\":0},{\"line\":2,\"ch\":7}],[{\"line\":3,\"ch\":0},{\"line\":3,\"ch\":7}],[{\"line\":4,\"ch\":0},{\"line\":4,\"ch\":7}],[{\"line\":5,\"ch\":0},{\"line\":5,\"ch\":7}],[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":7}],[{\"line\":1,\"ch\":0},{\"line\":1,\"ch\":7}],[{\"line\":2,\"ch\":0},{\"line\":2,\"ch\":7}],[{\"line\":3,\"ch\":0},{\"line\":3,\"ch\":7}],[{\"line\":4,\"ch\":0},{\"line\":4,\"ch\":7}],[{\"line\":5,\"ch\":0},{\"line\":5,\"ch\":7}],[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":7}],[{\"line\":1,\"ch\":0},{\"line\":1,\"ch\":7}],[{\"line\":2,\"ch\":0},{\"line\":2,\"ch\":7}],[{\"line\":3,\"ch\":0},{\"line\":3,\"ch\":7}],[{\"line\":4,\"ch\":0},{\"line\":4,\"ch\":7}],[{\"line\":5,\"ch\":0},{\"line\":5,\"ch\":7}]]"}
!@%STYLE%@!
Inspect mask definitions that use 1U << enumeration values to represent flags and construct empty or full sets. section 5.7.3

