VB.Net Tutorial/Data Type/Bit — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 15:54, 26 мая 2010
Bit Shift left and right
<source lang="vbnet">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</source>
4080 1020
Sign Bit
<source lang="vbnet">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</source>
Value after shift operation: -4096