c++ - How many options can I include in a bit mask? -
in this question pointed out that:
using int [for bit mask] asking trouble
i have been using unsigned char
store bitmask flags, occurs me hit low limit since char byte, 8 bits, 8 options in mask?
enum options{ k1=1<<0, k2=1<<1, .... through k8 } unsigned char myoption=k2;
do need make myoption
int
or other type example if wish store more 8 possible options (and combinations of options, of course, hence why using bit mask in first place)? what's best type?
#include <stdint.h>
this defines types fixed sizes not compiler specific.
int16_t = 16 bits
uint16_t = 16 bits unsigned
int32_t = 32 bits
if need more 64 flags should consider ::std::vector<> wayne uroda suggested.
Comments
Post a Comment