VB.NET位移位混乱
我有一些关于 VB.NET 位移位的问题。我理解 << >>
运算符是 VB.NET 中的位移运算符。
我有一个两字节的十六进制值 0x3ACC
,这两个字节中的每一位代表一天、一个月或一年。该十六进制值的位结构为yyyy yyym mmmd dddd
。
我很困惑应该如何对这些值进行位移位,以便年、月和日都在它们自己的 UINT16
值中。移位数字应该是什么?我需要在移位中添加任何填充吗?
I have some questions regarding VB.NET bit shifting. I understand the << >>
operators are bit shift operators in VB.NET.
I have a two-byte hex value, 0x3ACC
, and each bit in these two bytes represents either a day, month or year. The bit structure of this hex value is yyyy yyym mmmd dddd
.
I am confused as to how I should bit shift these values so that year, month and day are in their own UINT16
values. What should the shifting numbers be and do I need to add any padding to the shift?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将需要使用
And
以及位移操作来获得结果。您需要右移(计算金额的“非年份”位)才能仅获取年份。要获取日期,只需And
以及设置了所有“日期”位的值即可。提取月份需要结合使用两种技术,要么And
然后>>
或>>
然后并使用正确的面罩。
剧透:
0x3ACC >>> 9
0x3ACC 和 0x001F
0x3ACC 和 0x01E0 >>> 5
You're going to need to use
And
as well as the bit shifting operations to get your result. You need to shift right (count the "non-year" bits for the amount) to get just the year. To get the day, justAnd
with the value that has all the "day" bits set. Extracting the month will require a combination of the two techniques, eitherAnd
ing then>>
or>>
and thenAnd
ing with the correct mask.Spoilers:
0x3ACC >> 9
0x3ACC And 0x001F
0x3ACC And 0x01E0 >> 5