Enum flags over 2^32

前端 未结 3 1954
無奈伤痛
無奈伤痛 2021-02-02 05:06

I am using Enum flags in my application. The Enum can have around 50+ values, so values go up to 2^50. I was just wondering, can I use Math.Pow(2, variable) to calc

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-02 05:57

    If you change to using non-decimal notations where the powers of 2 are more regular then you will no longer need to generate them automatically, e.g.:

    // octal
    AL = 0001L,
    AK = 0002L,
    AZ = 0004L,
    AR = 0010L,
    CA = 0020L,
    CO = 0040L,
    CT = 0100L,
    ...
    
    // hexadecimal
    AL = 0x001L,
    AK = 0x002L,
    AZ = 0x004L,
    AR = 0x008L,
    CA = 0x010L,
    CO = 0x020L,
    CT = 0x040L,
    ...
    

提交回复
热议问题