VB.Net Tutorial/Data Type/Bit

Материал из VB Эксперт
Перейти к: навигация, поиск

Bit Shift left and right

public class Test
   public Shared Sub Main
        "&HFF = the hex value FF, which equals 255, and
        "1111 1111 in binary
        Dim numberToBeShifted As Integer = &HFF
        numberToBeShifted = numberToBeShifted << 4
        Console.WriteLine(numberToBeShifted)
        numberToBeShifted >>= 2
        Console.WriteLine(numberToBeShifted)
   End Sub
End class
4080
1020

Sign Bit

Option Strict On
Public Module SignBit
   Public Sub Main()
      Dim negValue As Integer = -1024
      " Save state of sign bit
      Dim signBit As Integer = negValue And &H80000000
      negValue = negValue << 2
      " Clear sign bit
      negValue = negValue And &H7FFFFFFF
      " Restore sign bit
      negValue = negValue Or signBit
      
      Console.WriteLine("Value after shift operation: {0}", negValue)
   End Sub
End Module
Value after shift operation: -4096