I have 65 different flags (options) for a custom data structure. Currently it looks like this:
struct CustomDataStruct {
int Something;
unsigned char Flags[9]
};
This way I'm able to store up to 72 flags (7 remaining, just in case I decide to add more). I want to use an individual bit for each flag, so I came up with this:
void SetFlag(struct CustomDataStructure* Struct, int FlagNr) {
// Error checking and other stuff here
int index = FlagNr / 8; array.
Struct->Flags[index] |= 1 << (__________);
}
I've already tried with 1 << (FlagNr % 8)
but it's not setting the correct bit. For example, I want to turn on flag ID 23 (starting from zero), so I call SetFlag(structInstance, 23)
, which correctly determines the index (Flags[2]), but 23 % 8
= 7
, and 1 << 7
= 1000 0000
(in binary), instead of the correct value, which should be 0000 0001
(turn on last bit of the 3rd uchar of the array, i.e bit no. 24).
Flags must be stored on this array, each bit representing the flag switch. Changing this is not an option.