|
Bit Flags
A Programming Pattern |
|
Prof. David Bernstein
|
| Computer Science Department |
| bernstdh@jmu.edu |
if
statements that will have boolean
expressions that involve the variables that represent the
items
boolean variable for each item
that is assigned true when the player has the item and
false otherwise
int is represented using multiple bits
&,
|, and ^ operators| operator, clear particular bits (i.e.,
make the bits 0) using the & operator, and/or
toggle particular bits (i.e., switch the bits to their other value)
using the ˆ operator| operator and a relational operator
00000001,00000010,00000100,
00001000,00010000,00100000,
and 01000000
| operator
00000001
| 01000000
________
01000001