# 11.18 Shift Operators

**Visual Studio .NET 2003**

The binary operators **<<** and **>>** perform bit shifting operations. The operators are defined for the **Byte**, **Short**, **Integer** and **Long** types. Unlike the other binary operators, the result type of a shift operation is determined as if the operator was a unary operator with just the left operand. The type of the right operand must be implicitly convertible to **Integer** and is not used in determining the result type of the operation.

The **<<** operator causes the bits in the first operand to be shifted left the number of places specified by the shift amount. The high-order bits outside the range of the result type are discarded and the low-order vacated bit positions are zero-filled.

The **>>** operator causes the bits in the first operand to be shifted right the number of places specified by the shift amount. The low-order bits are discarded and the high-order vacated bit positions are set to zero if the left operand is positive or to one if negative. If the left operand is of type **Byte**, the vacant high-order bits are zero-filled.

The shift operators shift the bits of the underlying representation of the first operand by the amount of the second operand. If the value of the second operand is greater than the number of bits in the first operand, or is negative, then the shift amount is computed as `RightOperand And SizeMask`

where `SizeMask`

is:

LeftOperand Type | SizeMask |
---|---|

Byte | 7 (`&H7` ) |

Short | 15 (`&HF` ) |

Integer | 31 (`&H1F` ) |

Long | 63 (`&H3F` ) |

If the shift amount is zero, the result of the operation is identical to the value of the first operand. No overflows are possible from these operations.

ShiftOperatorExpression ::= Expression << Expression | Expression >> Expression

#### See Also

11.12.1 Operator Precedence and Associativity | 11.12.2 Object Operands | 11.12.3 Operator Resolution | 11.13 Arithmetic Operators | 11.14 Relational Operators | 11.15 Like Operator | 11.16 Concatenation Operator | Operators Listed by Functionality (Visual Basic Language Reference)