>>= Operator (Visual Basic)

Performs an arithmetic right shift on the value of a variable or property and assigns the result back to the variable or property.

variableorproperty >>= amount

Parts

  • variableorproperty
    Required. Variable or property of an integral type (SByte, Byte, Short, UShort, Integer, UInteger, Long, or ULong).

  • amount
    Required. Numeric expression of a data type that widens to Integer.

Remarks

The element on the left side of the >>= operator can be a simple scalar variable, a property, or an element of an array. The variable or property cannot be ReadOnly (Visual Basic). The >>= operator assigns the value on its right to the variable or property on its left.

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 bit is propagated into the bit positions vacated at the left. This means that if variableorproperty has a negative value, the vacated positions are set to one. If variableorproperty is positive, or if its data type is an unsigned type, the vacated positions are set to zero.

Overloading

The >> Operator (Visual Basic) 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. Overloading the >> operator affects the behavior of the >>= operator. If your code uses >>= on a class or structure that overloads >>, be sure you understand its redefined behavior. For more information, see Operator Procedures (Visual Basic).

Example

The following example uses the >>= operator to shift the bit pattern of an Integer variable right by the specified amount and assign the result to the variable.

Dim var As Integer = 10
Dim shift As Integer = 2
var >>= shift
' The value of var is now 2 (two bits were lost off the right end).

See Also

Reference

>> Operator (Visual Basic)

Assignment Operators (Visual Basic)

Bit Shift Operators (Visual Basic)

Operator Precedence in Visual Basic

Operators Listed by Functionality (Visual Basic)

Other Resources

Statements in Visual Basic

Change History

Date

History

Reason

August 2012

Fixed code comment in example.

Customer feedback.