3 ms·
Another take on this is using hex values. Not saying it's better or worse than bit shifting, but it is fairly clear to me. My current lead prefers this for flag
by bryondowd 10y ago
Another take on this is using hex values. Not saying it's better or worse than bit shifting, but it is fairly clear to me. My current lead prefers this for flag definitions.
FIRST_FLAG = 0x00000001
SECOND_FLAG = 0x00000002
THIRD_FLAG = 0x00000004
FOURTH_FLAG = 0x00000008
FIFTH_FLAG = 0x00000010
SIXTH_FLAG = 0x00000020
SEVENTH_FLAG = 0x00000040
EIGHTH_FLAG = 0x00000080
NINTH_FLAG = 0x00000100
...
28TH_FLAG = 0x08000000
29TH_FLAG = 0x10000000
30TH_FLAG = 0x20000000
Of course, I've never needed more than 12 bits of flags concurrently.
EDIT: Bleh, it wiped out my white space. These should be aligned.
- astrodust 10y agoAt some point you forget a zero and it all goes to hell. Using 1 << n is far more concise.
- bryondowd 10y agoProbably true. But assuming they are aligned, as they should be, a missing 0 would be pretty obvious. The real gotcha would be accidentally leaving a character in the wrong column during a copy-paste job. But really, I've only used this with two or three character hex codes, so it works out much better. 0x01 through 0x80 are pretty hard to mess up, and 0x001 through 0x800 isn't bad either. But yeah, the bit shifting honestly is probably a better solution. Cleaner, more scale-able.