| Bitwise shift operators ('<<' and '>>')

Previous | Binary operators | Next

Bitwise shift operators in C use the following syntax:

    expr1 << expr2
    expr1 >> expr2

In the expressions expr1 << expr2 and expr1 >> expr2, the operands expr1 and expr2 must be of integral type. The normal integral promotions are performed on expr1 and expr2, and the type of the result is the type of the promoted expr1. If expr2 is negative or is greater than or equal to the width in bits of expr1, the operation is undefined.
The result of the operation expr1 << expr2 is the value of expr1 left-shifted by expr2 bit positions, zero-filled from the right if necessary. The result of the operation expr1 >> expr2 is the value of expr1 right-shifted by expr2 bit positions.