...
[DayOfMonth(28)]
D28 = 134217728L,
[DayOfMonth(29)]
D29 = 268435456L,
[DayOfMonth(30)]
D30 = 536870902L,
[DayOfMonth(31)]
D31 = 1073741824L,
[DayOfMonth(DayOfMonthAttribute.LastDayOfMonth)]
Last = 2147483648L
Vs ...
[DayOfMonth(28)]
D28 = 1 << 28,
[DayOfMonth(29)]
D29 = 1 << 29,
[DayOfMonth(30)]
D30 = 1 << 31,
[DayOfMonth(31)]
D31 = 1 << 31,
[DayOfMonth(DayOfMonthAttribute.LastDayOfMonth)]
Last = 1 << 32
Hint: It's with D30 in both cases...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.
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.
I might be a bit weird, but I know the powers of 2 up to 2^20 in decimal. They've just snuck in there over the years, along with 2^24 and 2^31. So if I need some powers of two I might well just type them out like that. I can recognise a few common combinations too... it is all much easier in hex though.
I should really get the full set up to 2^64 memorised...
You're making it clear these are flags and you're concerned with individual bits. 2, 4, 8 etc. are decimal numbers and mean something else i.e. "two", "four", "eight".
Does bitwise ORing the decimal numbers 2 and 4 really make sense? Not particularly, but combining bits at certain offset does.
// State flags
enum EGlassRNState
{
EGlassRNState_Initial = 0,
EGlassRNState_Weakened = 1 << 0,
EGlassRNState_Shattering = 1 << 1,
EGlassRNState_Shattered = 1 << 2,
EGlassRNState_ActiveFrags = 1 << 3
};
foreach(var val in Enum.GetValues(typeof(EGlassRNState
)))
{
Console.WriteLine($"{val} -> {(int)val}");
}Output:
EGlassRNState_Initial -> 0
EGlassRNState_Weakened -> 1
EGlassRNState_Shattering -> 2
EGlassRNState_Shattered -> 4
EGlassRNState_ActiveFrags -> 8 writable = 001
readable = 010
readwrite = 011 (writable | readable)But it's also still in the process of Shattering, so when I jump through it, I'm risking cuts, it's actively producing noise for someone to hear, that laser I'm shining at it will be fragmenting wildly rather than reflecting off/passing through/deflecting like it was before the glass started Shattering.
Anyway, I don't think it's worth arguing design on this codebase because it is full of dirty things.
e.g.
EGlassRNState allowed = EGlassRNState_Initial | EGlassRNState_Shattered;
EGlassRNState current = EGlassRNState_Initial;