Search code examples
vb.net16-bituint

How to shift a bits in a Ushort 16 bit integer in VB.NET?


I have a 16 bit unsigned integer and its values are like this:

byte_val1 = 1000000000000001

From this I need to right shift this and make it like this:

  1100000000000000

I have done this:

 byte_val1 = byte_val1 >> 1

and getting byte_val1 = 100000000000000.

After that I did

  byte_val1 = byte_val1 Or &H80

but I didn't get the desired result... Instead I got 100000010000000.

So what should I do to get that result?


Solution

  • I got it right this time. I did this:

    byte_val1 = byte_val1 >> 1
    
    byte_val1 = byte_val1 Or &H8000
    

    And it worked.