vb.net - 十六进制,按位问题

发布于 2024-10-30 23:56:03 字数 341 浏览 0 评论 0原文

我试图弄清楚如何计算两个十六进制数的低 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

过度放纵 2024-11-06 23:56:03

该代码转换为以下 VB 代码:

serialBytes(2) = &h64 And &h7F
serialBytes(3) = (&h64 >> 7) And &h7F

如果十六进制值 64 实际上是变量输入,只需将 &h64 替换为输入变量即可。如果输入是整数,则必须将结果转换为字节:

serialBytes(2) = CType(value And &H7F, Byte)
serialBytes(3) = CType((value >> 7) And &H7F, Byte)

The code translates into this VB code:

serialBytes(2) = &h64 And &h7F
serialBytes(3) = (&h64 >> 7) And &h7F

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:

serialBytes(2) = CType(value And &H7F, Byte)
serialBytes(3) = CType((value >> 7) And &H7F, Byte)
很酷不放纵 2024-11-06 23:56:03

VB.NET 没有位移运算符,但有按位运算符 并且:

set bits1to7  = value And &H007F
set bits8to14 = value And &H3F80

编辑:

自 .NET Framework 1.1 以来,VB.NET 确实有位移运算符(我的错),因此更系统的方法是确实也有可能:

set bits1to7  = value And &H7F
set bits8to14 = (value >> 7) And &H7F

VB.NET has no bit shift operators, but does have the bitwise operator And:

set bits1to7  = value And &H007F
set bits8to14 = value And &H3F80

Edit:

VB.NET does have bit shift operators (my bad) since .NET Framework 1.1, so the more systematic approach is indeed also possible:

set bits1to7  = value And &H7F
set bits8to14 = (value >> 7) And &H7F
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文