Bitwise Shift Arithmetic Right '~>', '~>='

The Bitwise Shift Arithmetic Right operator is just like the Shift Right operator except that it maintains the sign, like a divide by 2, 4, 8, etc on a signed value. Bitwise Shift Arithmetic Right can be used in variable and integer constant expressions, but not in floating-point constant expressions. Example:

X := Y ~> 4

The above example shifts Y right by 4 bits, maintaining the sign. If Y is -3200 (%11111111 11111111 11110011 10000000) then -3200 ~> 4 = -200 (%11111111 11111111 11111111 00111000). If the same operation had been done with the Shift Right operator instead, the result would have been 268,435,256 (%00001111 11111111 11111111 00111000).

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

X ~>= 2'Short form of X := X ~> 2

Here, the value of X is shifted right 2 bits, maintaining the sign, and the result is stored back in X. The assignment form of Bitwise Shift Arithmetic Right 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.