Topic: DMD0349

Help File Version: 2.9.4.37

Math Shift Left Operator

 

The Math Shift Left operator ( << ) causes the bits in left operand to be shifted to the left by the number of positions specified by the right operand. A left shift is a logical shift which means that the bits that are shifted off the end are discarded, including the sign bit. The bit positions that have been vacated by the left shift operation are zero-filled.

 

The number of bit positions to shift should be between 1 and the maximum number of bit positions in the value to be shifted. Executing a Left Shift with a bit count higher than the number of bit positions in the value to be shifted is not an error but will yield a result of 0. Executing a Left Shift by 0 bits has no effect on the shifted value.

 

Note: executing a Left Shift with a negative value for the bit count is undefined and the result will always be 0.

 

Note: Left Shift operations should only be used with unsigned hexadecimal values and unsigned integer memory locations, it is NOT intended for use with Signed integer values or Real values because the result is not useful.

 

Traditional math precedence rules are used to solve the math expression, The use of parentheses to remove any ambiguity in the processing order is encouraged.

 

Unsigned Integers: assume V0 = 0x1234

 

V1 = V0 << 5

 

V1 = 0x1234 << 5

 

0001_0010_0011_0100 - initial bit pattern

0100_0110_1000_0000 - after 5th left shift

 

V1 = 0x4680

 

One operand is an unsigned integer memory locations, the other is an integer constant.

 

The upper 5 bits are shifted out. The remaining 11 bits are shifted into the uppermost 11 bit positions. The bottom 5 positions are filled with 0's.

 

The result is placed in an unsigned integer memory location.

 

 


See Also:

Add

Subtract

Multiply

Divide

 

Modulus / Remainder

Raise to a Power

 

Less Than

Less than or Equal To

 

Equal To

Not Equal To

 

Greater Than

Greater Than or Equal To

 

Logical AND

Logical OR

 

Bit-wise AND

Bit-wise OR

Bit-wise XOR

 

Shift Left

Shift Right

Unsigned Shift Right

 

Negate

Bit-wise Invert

Logical NOT

 


Related Topics:

MATH - Calculate Expression