vb.net - 十六进制,按位问题
我试图弄清楚如何计算两个十六进制数的低 7 位和 7-13 位。
下面是一些示例 C 代码,只需在 vb.net 中使用:
serialBytes[2] = 0x64 & 0x7F; // Second byte holds the lower 7 bits of target.
serialBytes[3] = (0x64 >> 7) & 0x7F; // Third data byte holds the bits 7-13 of target
0x7F 是一个常量,因此根据输入改变的唯一数字是 0x64。
有人可以帮我吗?
I'm trying to figure out how to calculate the lower 7 bits and 7-13 bits of two hex numbers.
Here is some example c code, just need this in vb.net:
serialBytes[2] = 0x64 & 0x7F; // Second byte holds the lower 7 bits of target.
serialBytes[3] = (0x64 >> 7) & 0x7F; // Third data byte holds the bits 7-13 of target
The 0x7F is a constant so the only number that changes based off input is the 0x64.
Can someone help me out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该代码转换为以下 VB 代码:
如果十六进制值
64
实际上是变量输入,只需将&h64
替换为输入变量即可。如果输入是整数,则必须将结果转换为字节:The code translates into this VB code:
If the hex value
64
is actually a variable input, just replace&h64
with the input variable. If the input is an integer, you have to cast the results to byte, though:VB.NET 没有位移运算符,但有按位运算符 并且:
编辑:
自 .NET Framework 1.1 以来,VB.NET 确实有位移运算符(我的错),因此更系统的方法是确实也有可能:
VB.NET has no bit shift operators, but does have the bitwise operator And:
Edit:
VB.NET does have bit shift operators (my bad) since .NET Framework 1.1, so the more systematic approach is indeed also possible: