我怎样才能做一个按位与操作VB.NET? [英] How can I do a bitwise-AND operation in VB.NET?

查看:873
本文介绍了我怎样才能做一个按位与操作VB.NET?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想执行一个VB.NET按位与操作,以短(16位)变量,AND运算将其与0000000011111111(因此只保留了最低显著字节/ 8最低显著位)。

I want to perform a bitwise-AND operation in VB.NET, taking a Short (16-bit) variable and ANDing it with '0000000011111111' (thereby retaining only the least-significant byte / 8 least-significant bits).

我该怎么办呢?

推荐答案

0000000011111111重新$ P $为&放大器; HFF(或放大器; H00FF如果你想明确),和普通AND运算符的实际上位运算符。所以要屏蔽掉一个短期的顶部字节,你会写:

0000000011111111 represented as a VB hex literal is &HFF (or &H00FF if you want to be explicit), and the ordinary AND operator is actually a bitwise operator. So to mask off the top byte of a Short you'd write:

shortVal = shortVal AND &HFF

为了得到一个二进制常量到VB的更具创造性的方法,请参阅: VB.NET指定二进制常量

这篇关于我怎样才能做一个按位与操作VB.NET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆