>> Operator (Visual Basic)
Performs an arithmetic right shift on a bit pattern.
Required. Integral numeric value. The result of shifting the bit pattern. The data type is the same as that of pattern.
Required. Integral numeric expression. The bit pattern to be shifted. The data type must be an integral type (SByte, Byte, Short, UShort, Integer, UInteger, Long, or ULong).
Required. Numeric expression. The number of bits to shift the bit pattern. The data type must be Integer or widen to Integer.
Arithmetic shifts are not circular, which means the bits shifted off one end of the result are not reintroduced at the other end. In an arithmetic right shift, the bits shifted beyond the rightmost bit position are discarded, and the leftmost (sign) bit is propagated into the bit positions vacated at the left. This means that if pattern has a negative value, the vacated positions are set to one; otherwise they are set to zero.
Note that the data types Byte, UShort, UInteger, and ULong are unsigned, so there is no sign bit to propagate. If pattern is of any unsigned type, the vacated positions are always set to zero.
To prevent shifting by more bits than the result can hold, Visual Basic masks the value of amount with a size mask corresponding to the data type of pattern. The binary AND of these values is used for the shift amount. The size masks are as follows:
Data type of pattern
Size mask (decimal)
Size mask (hexadecimal)
If amount is zero, the value of result is identical to the value of pattern. If amount is negative, it is taken as an unsigned value and masked with the appropriate size mask.
Arithmetic shifts never generate overflow exceptions.
The >> operator can be overloaded, which means that a class or structure can redefine its behavior when an operand has the type of that class or structure. If your code uses this operator on such a class or structure, be sure you understand its redefined behavior. For more information, see Operator Procedures (Visual Basic).
The following example uses the >> operator to perform arithmetic right shifts on integral values. The result always has the same data type as that of the expression being shifted.