如何在 VB.NET 中按位移位?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1417645/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 14:25:33  来源:igfitidea点击:

How to bitwise shift in VB.NET?

vb.netoperatorsbit-manipulationbit-shift

提问by TheFlash

How do I bitwise shift right/left in VB.NET? Does it even have operatorsfor this, or do I have to use some utility method?

如何在 VB.NET 中按位右移/左移?它甚至有运营商,还是我必须使用一些实用方法?

回答by Mehrdad Afshari

VB.NET has had bit shift operators (<<and >>) since 2003.

自 2003 年以来,VB.NET 就有了位移运算符(<<>>)。

回答by TheFlash

You can use the <<and >>operators, and you have to specify how many bits to shift.

您可以使用<<>>运算符,并且必须指定要移位的位数。

myFinal = myInteger << 4   ' Shift LEFT by 4 bits.
myFinal = myInteger >> 4   ' Shift RIGHT by 4 bits.

You can also use it as a unary operator...

您也可以将其用作一元运算符...

myFinal <<= 4     ' Shift myFinal LEFT by 4 bits, storing the result in myFinal.
myFinal >>= 4     ' Shift myFinal RIGHT by 4 bits, storing the result in myFinal.