How to bitwise shift in VB.NET?

前端 未结 2 970
借酒劲吻你
借酒劲吻你 2021-01-17 23:23

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

相关标签:
2条回答
  • 2021-01-18 00:03

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

    0 讨论(0)
  • 2021-01-18 00:09

    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.
    
    0 讨论(0)
提交回复
热议问题