Bitfields are just basically integer types, yeah. Bitwise operators let you treat each bit of the number separately, since all types are internally represented binary numbers.
On 32-bit machines, you'd be able to pack 32 boolean flags into a single int. And 64-bit allow 64 separate boolean flags. Well, sort of. There's a few details you'll need to worry about.
(Technical sidenote! It all depends on your compiler and platform, since the standards only require minimum capacities for each primitive. A lot of the time though, an int is exactly the word size of the CPU you're using. You might want to get some typedefs going to ensure the proper bit length of your bitfield. So something like u8 for unsigned 8-bit, u32 for unsigned 32-bit. There are plenty of headers you can find that typedef to proper sizes for you. Since this is C++ you mentioned, there is a chance your particular compiler might not obey C99 standards, so it might not have uint32_t. But with enough conditionally-compiled typedefs, you can get something! Or you can just assume an int is 32-bit, which it probably will be on your machine anyways.)
Each bit corresponds to a power of two in binary. So your individual bits are addressed by: 1, 2, 4, 8, 16, 32, 64, and so on. Or to save time writing, use hexadecimal: 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80, 0x100, 0x200, ...
And if you're using a 32-bit unsigned int, the highest bit index is 2**31 (2,147,483,648 or 0x80000000).
When all bits are off, you have a value of 0 in your bitfield.
When all bits are on, you get a value of 2**31-1 (4,294,967,295 or 0xFFFFFFFF).
Let's start by declaring an int we intend to manipulate with bitwise operators. Make sure it's unsigned, or else you have a sign-bit to account for too.
If you want to "turn on" a bit in a bitfield, you use a bitwise OR (|).
b |= 1;
b |= 3; // Turns on bits 1 and 2 at the same time.
To "toggle" a bit, use bitwise exclusive or / XOR (^)
b ^= 4; // Turns the bit on!
b ^= 4; // Turns it off.
To "test" if a bit is on, use bitwise AND (&)
//Check if bit at 2 is on.
if (b & 2 == 2)
{
// The bits were on.
}
To "invert" the bits of a number, use bitwise NOT (~).
To "turn off" a bit, you use bitwise and combined with bitwise not, also called NAND (&~).
To "shift" the bits left, or right, use << and >>.
This is equivalent to multiplying a number by (2**n) when shifting left.
and is equivalent to dividing a number by (2**n) when shifting right.
Bitshifts are kind of complicated, but they are very handy for fixed-point math.
b <<= 2; // Multiply by 4, or... move the bits left two digits.
b >>= 3; // Divide by 8, or move the bits right three digits.
There are more tricks, too. But this should be enough to get you started.
That said, I'd still recommend a bunch of separate booleans, since it's more trouble than it's worth. That said, it does yield performance gains.
EDIT: some modifications due to a few things that weren't quite true in my explanation. There are plenty of nitpicky details, due to the fact this is low-level stuff. So be careful. Thanks, everyone!