Results of VeriStand’s Left Shift Function (<<) for Out-of-Range Parameters

Updated Aug 29, 2018

Reported In

Software

  • VeriStand

Issue Details

I want to use arithmetic shift operations in VeriStand's Real-Time Expressions. What happens when I left-shift a value by more bits than the value contains? E.g. what is the result when I have a 32-bit value x and execute "x << 32"?

Solution

The behavior of the arithmetic left shift (<<) operation is different for 32-bit and 64-bit parameters.

32-bit
For 32-bit values, only the lowest 5 bits of the right operand are evaluated. Like using a bitmask of 0x0000[...]0011111. As a result, x << 32 has no effect and outputs x, in the case that x is e.g. of type U32.

64-bit
For 64-bit arithmetic left shift operations, all bits of the right operand are evaluated. Therefore e.g. x << 64 always outputs 0 in case x is e.g. of type U64.

Additional Information

Please note that the masking performed by the 32-bit operation makes e.g. x << 33 equal to x << 1.

WAS THIS ARTICLE HELPFUL?

Not Helpful