Left shifts the value of a variable by the number of bits specified in the value of an expression and assigns the result to the variable.

result |

# Arguments

*result*-
Any numeric variable.

*expression*-
Any numeric expression.

# Remarks

Using this operator is almost the same as specifying `result = result << expression`

, except that *result* is only evaluated once.

The **<<=** operator shifts the bits of *result* left by the number of bits specified in *expression*. The operator masks *expression* to avoid shifting *result* by too much. Otherwise, if the shift amount exceeded the number of bits in the data type of *result*, all the original bits would be shifted away to give a trivial result. To ensure that each shift leaves at least one of the original bits, the shift operators use the following formula to calculate the actual shift amount: mask *expression* (using the bitwise AND operator) with one less than the number of bits in *result*.

# Example

For example:

В | Copy Code |
---|---|

var temp temp = 14 temp |

The variable *temp* has a value of 56 because 14 (00001110 in binary) shifted left two bits equals 56 (00111000 in binary). Bits are filled in with zeroes when shifting.

To illustrate how the masking works, consider the following example.

В | Copy Code |
---|---|

var x : byte = 15; // A byte stores 8 bits. // The bits stored in x are 00001111 x |