BitRShift

Description

Shift a given decimal number num right by the specified number of bits shift. It is proceeded as follows: firstly convert num into its binary representation, remove shift digits from the rightmost digit of the binary, and then convert it back to the decimal number. For example, BitRShift (4,2) converts 4 into "100" (its binary value), removes the last 2 digits so it become 1 in binary, and then convert 1 (binary value) to 1 in decimal.

Syntax

int BitRShift(int num, int shift)

Parameters

num

The number in the decimal representation. It must be a non-negative integer.

shift

The number of bits by which to shift num right. It should be a non-negative integer. If a negative value is given, it will return the same value as the absolute value of shift of the BitLShift function.

Return

Returns a number shifted right by the specified number of bits.

Example

BitRShift(100, 2) = ;  // returns 25

See Also

BitLShift