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

Rob*_*cks 9 vb.net bit-manipulation operators bit-shift

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

Meh*_*ari 16

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


Rob*_*cks 7

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

myFinal = myInteger << 4   ' Shift LEFT by 4 bits.
myFinal = myInteger >> 4   ' Shift RIGHT by 4 bits.
Run Code Online (Sandbox Code Playgroud)

您也可以将它作为一元运算符使用...

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.
Run Code Online (Sandbox Code Playgroud)