Documentation/Calc Functions/BITRSHIFT

    From The Document Foundation Wiki


    Function name:

    BITRSHIFT

    Category:

    Mathematical

    Summary:

    Right shifts a non-negative integer value by the specified number of bits.

    Syntax:

    BITRSHIFT(Number; Shift)

    Returns:

    Returns a non-negative integer, that is the original number shifted by the specified number of bits.

    Arguments:

    Number is an integer in the range [0, 248-1], or a reference to a cell containing that number, that is the value to be shifted.

    Shift is an integer, or a reference to a cell containing that number, that is the number of bit positions to shift. If Shift is positive, then Number is shifted to the right. If Shift is negative, then Number is shifted to the left and this would be equivalent to BITLSHIFT(Number; -Shift).

    • If either Number or Shift is non-numeric, then BITRSHIFT reports a #VALUE! error.
    • If either Number or Shift is a non-integer value, then BITRSHIFT converts it to an integer by taking its floor value.
    • If Number is less than 0 or greater than 248-1, then BITRSHIFT reports an invalid argument error (Err:502).

    Additional details:

    • A right shift by N (N > 0) is equivalent to dividing by 2N and taking the floor value of the result. This effectively adds zeros at the left end of the binary representation of the number and drops digits from the right end.
    • More information is available on Wikipedia’s Bitwise operation page.
    • 248 is equal to 281474976710656.

    Examples:

    Formula Description Returns
    =BITRSHIFT(15; 3) 15 is binary 1111. The function shifts this value right by three bits, to give binary 1 or decimal 1. 1
    =BITRSHIFT(D1; D2) where cells D1 and D2 contain the numbers 6 and -1 respectively. 6 is binary 0110. Because the Shift argument is negative, the function shifts the value 6 left by one bit, to give binary 1100 or decimal 12. 12
    =BITRSHIFT(15.123; 3.9) The floor values of the two arguments are taken, giving 15 (binary 1111) and 3. The function shifts the value 15 right by three bits, to give binary 1 or decimal 1. 1

    Related LibreOffice functions:

    BITAND

    BITLSHIFT

    BITOR

    BITXOR

    ODF standard:

    Section 6.6.5, Part 2

    Related (or similar) Excel functions:

    BITRSHIFT since v.2013.