FlagsAttribute 枚举问题
所以我正在构建一个 MSNP(Windows Live Messenger)客户端。我
public enum UserCapabilities : long
{
None = 0,
MobileOnline = 1 << 0,
MSN8User = 1 << 1,
RendersGif = 1 << 2,
....
MsgrVersion7 = 1 << 30,
MsgrVersion8 = 1 << 31,
MsgrVersion9 = 1 << 32,
}
在这里得到了完整的功能列表 http://paste.pocoo.org/show/ 383240/
服务器将每个用户的能力作为一个长整数发送给客户端,我将其转换为 UserCapability
capabilities = Int64.Parse(e.Command.Args[3]);
user._capabilities = (UserCapabilities)capabilities;
这很好,并且对于至少一个用户(能力值为 1879474220),我可以
Debug.WriteLine(_msgr.GetUser(usr).Capabilities);
这样 做这将输出
RendersGif, RendersIsf, SupportsChunking, IsBot, SupportsSChannel, SupportsSipInvite, MsgrVersion5, MsgrVersion6, MsgrVersion7
但是对于另一个具有能力值(3055849760)的用户,当我做同样的事情时,我只是得到相同的输出数字
3055849760
我希望看到的是能力列表,就像其他用户一样用户。
我确信发生这种情况有一个非常正当的理由,但无论我如何努力向谷歌表达这个问题,我都找不到答案。
请帮我 :)
So I'm building an MSNP (windows live messenger) client. And I've got this list of capabilities
public enum UserCapabilities : long
{
None = 0,
MobileOnline = 1 << 0,
MSN8User = 1 << 1,
RendersGif = 1 << 2,
....
MsgrVersion7 = 1 << 30,
MsgrVersion8 = 1 << 31,
MsgrVersion9 = 1 << 32,
}
full list here http://paste.pocoo.org/show/383240/
The server sends each users capabilities to the client as a long integer, which I take and cast it to UserCapabilities
capabilities = Int64.Parse(e.Command.Args[3]);
user._capabilities = (UserCapabilities)capabilities;
This is fine, and with atleast one user (with a capability value of 1879474220), I can do
Debug.WriteLine(_msgr.GetUser(usr).Capabilities);
and this will output
RendersGif, RendersIsf, SupportsChunking, IsBot, SupportsSChannel, SupportsSipInvite, MsgrVersion5, MsgrVersion6, MsgrVersion7
But with another user, who has the capability value of (3055849760), when I do the same, I just get the same number outputted
3055849760
What I would like to be seeing is a list of capabilities, as it is with the other user.
I'm sure there is a very valid reason for this happening, but no matter how hard I try to phrase the question to Google, I am not finding an answer.
Please help me :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
移位运算符的定义意味着对于 32 位数字仅使用 5 个最低有效位,对于 64 位数字仅使用前 6 位;含义:
与
(均为
32
)相同通过将其设置为:
将其设置为 64 位数字,这就是 @leppie 修复的原因作品;否则
<<
被视为第一个(请注意1<<32
< em>等同于1<<0
,即1
),并且然后< /strong> 将结果1
转换为long
;所以它仍然是1
。ECMA 规范第 14.8 节中:
The definition of the shift operators means that only the 5 least significant bits are used for 32-bit numbers and only the first 6 bits for 64-bit; meaning:
is identical to
(both are
32
)By making it:
you make it a 64-bit number, which is why @leppie's fix works; otherwise the
<<
is considered first (and note that1<<32
is identical to1<<0
, i.e.1
), and then the resulting1
is converted to along
; so it is still1
.From §14.8 in the ECMA spec:
问题可能是算术溢出。
具体位于:
我建议您这样做:
以防止意外溢出。
更新:
看起来可能是较小的数字“触及”31 位,而较大的数字“触及”32 位。
The problem could be with arithmetic overflow.
Specifically at:
I suggest you make it:
To prevent accidental overflow.
Update:
Seems likely as the smaller number on 'touches' 31 bits, while the bigger one 'touches' 32 bits.