Bitwise Left Shift Assignment Operator C++
The bitwise shift operators are as follows:
Right shift (>>)
Left shift (<<)
Both operands of the shift operators must be of integral types. Integral promotions are performed according to the rules described in Integral Promotions. The type of the result is the same as the type of the promoted left operand. The value of a right-shift expression x >> y is x / 2y, and the value of a left-shift expression x << y is x * 2y.
The result is undefined if the right operand of a shift expression is negative or if the right operand is greater than or equal to the number of bits in the (promoted) left operand.
The left-shift operator causes the bit pattern in the first operand to be shifted to the left by the number of bits specified by the second operand. Bits vacated by the shift operation are zero-filled. This is a logical shift instead of a shift-and-rotate operation.
The right-shift operator causes the bit pattern in the first operand to be shifted to the right by the number of bits specified by the second operand. Bits vacated by the shift operation are zero-filled for unsigned quantities. For signed quantities, the sign bit is propagated into the vacated bit positions. The shift is a logical shift if the left operand is an unsigned quantity; otherwise, it is an arithmetic shift.
The result of a right shift of a signed negative quantity is implementation-dependent. Although Microsoft C++ propagates the most-significant bit to fill vacated bit positions, there is no guarantee that other implementations will also do so.
- 2 minutes to read
Moves the specified number of bits to the left and assigns the result to . The bits vacated by the operation are filled with 0.
The number of bits to move.
Using the operator is the same as specifying
The following example shows how to use the operator.
Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards, Internet Explorer 11 standards. Also supported in Store apps (Windows 8 and Windows Phone 8.1). See Version Information.
Bitwise Left Shift Operator (<<)
Bitwise Right Shift Operator (>>)
Unsigned Right Shift Operator (>>>)