嗨,有人可以给我一些帮助,这是我的Enum代码
Enum _WSC_SECURITY_PROVIDER
WSC_SECURITY_PROVIDER_FIREWALL = &H1
WSC_SECURITY_PROVIDER_AUTOUPDATE_SETTINGS = &H2
WSC_SECURITY_PROVIDER_ANTIVIRUS = &H4
WSC_SECURITY_PROVIDER_ANTISPYWARE = &H8
WSC_SECURITY_PROVIDER_INTERNET_SETTINGS = &H16
WSC_SECURITY_PROVIDER_USER_ACCOUNT_CONTROL = &H32
WSC_SECURITY_PROVIDER_SERVICE = &H64
WSC_SECURITY_PROVIDER_NONE = &H0
End Enum
Enum _WSC_SCANNER_SETTINGS
SCANNER_UNKNOWN = &H1
SCANNER_RUNNING = &H16
End Enum
Enum _WSC_UPTODATE
up_To_Date = &H0
too_Old = &H10
End Enum
所以我得到这个十六进制值:61100在二进制中是:1100001000100000000,我希望我的输出是
WSC_SECURITY_PROVIDER_ANTIVIRUS + WSC_SECURITY_PROVIDER_AUTOUPDATE_SETTINGS + ???? + up_To_Date
到现在为止,我只有这个,但它没有做我想做的事情
Dim _security As _WSC_SECURITY_PROVIDER = hex.Substring(0, 2)
Dim _scanner As _WSC_SCANNER_SETTINGS = hex.Substring(2, 2)
Dim _uptodate As _WSC_UPTODATE = hex.Substring(4, 2)
Console.WriteLine("_security={0}, _scanner={1}, _uptodate={2}",
_security,
_scanner,
_uptodate
)
我会很感激提示。
答案 0 :(得分:0)
如果您正在设计一个用于表示标志,单个位的枚举,则枚举中的项应为2的幂,十六进制16为三位。我创建这个枚举作为模板,所以我不需要做很多打字。只需更改名称即可。
<FlagsAttribute()> _
Public Enum bit As Integer
none = 0
s0 = 1 << 0
s1 = 1 << 1
s2 = 1 << 2
s3 = 1 << 3
s4 = 1 << 4
s5 = 1 << 5
s6 = 1 << 6
s7 = 1 << 7
s8 = 1 << 8
s9 = 1 << 9
s10 = 1 << 10
s11 = 1 << 11
s12 = 1 << 12
s13 = 1 << 13
s14 = 1 << 14
s15 = 1 << 15
s16 = 1 << 16
s17 = 1 << 17
s18 = 1 << 18
s19 = 1 << 19
s20 = 1 << 20
s21 = 1 << 21
s22 = 1 << 22
s23 = 1 << 23
s24 = 1 << 24
s25 = 1 << 25
s26 = 1 << 26
s27 = 1 << 27
s28 = 1 << 28
s29 = 1 << 29
s30 = 1 << 30
all = -1
End Enum
通常我会注释掉未使用过的物品,但留下它们。