Shifts a number's bits to the right, maintaining sign.

Syntax

BITRSHIFT(<int expN>, <shift expN>)

<int expN>

A signed 32-bit integer.

<shift expN>

The number of places to shift, from 0 to 32.

Description

Unlike the other bitwise functions, BITRSHIFT( ) treats its 32-bit integer as a signed 32-bit integer. The sign of a 32-bit integer is stored in the most significant bit (bit 31), which is also referred to as the high bit. If the high bit is 1, the number is negative if it is treated as a signed integer. Otherwise, it is simply a very large unsigned integer.

BITRSHIFT( ) moves each bit in the numeric value <int expN> to the right the number of times you specify in <shift expN>. Each time the bits are shifted, the previous value of the high bit is restored, and the least significant bit (bit 0, the bit farthest to the right) is lost. This is called a sign-extended shift, because the sign is maintained.

A similar function, BITZRSHIFT( ), performs a zero-fill right shift, which always sets the high bit to zero. If <int expN> is a positive integer less than 2^31, BITZRSHIFT( ) and BITRSHIFT( ) have the same effect, because the high bit for such an integer is zero.

Use BITRSHIFT( ) when you’re treating the integer as a signed integer. Use BITZRSHIFT( ) when the integer is unsigned.

Shifting a number’s bits to the right once has the effect of dividing the number by two, dropping any fractions.