Bitwise Shift Left '<<', '<<='

The Bitwise Shift Left operator shifts the bits of the first operand left by the number of bits indicated in the second operand. The original MSBs (leftmost bits) drop off and the new LSBs (rightmost bits) are set to zero. Bitwise Shift Left can be used in both variable and integer constant expressions, but not in floating-point constant expressions. Example:

X := Y << 2

If Y started out as:

%10000000 01110000 11111111 00110101

...the Bitwise Shift Left operator would shift that value left by two bits, setting X to:

%00000001 11000011 11111100 11010100

Since the nature of binary is base-2, shifting a value left is like multiplying that value by powers of two, 2b, where b is the number of bits shifted.

Bitwise Shift Left has an assignment form, <<=, that uses the variable to its left as both the first operand and the result destination. For example,

X <<= 4'Short form of X := X << 4 

Here, the value of X is shifted left four bits and is stored back in X. The assignment form of Bitwise Shift Left may also be used within expressions for intermediate results; see Intermediate Assignments.

Unless otherwise noted, content on this site is licensed under the
Creative Commons Attribution-ShareAlike 4.0 International License.