The Google Sheets BITRSHIFT function shifts the bits of a number to the right by a specified amount, effectively dividing the number by powers of 2. For example, =BITRSHIFT(8, 1) returns 4, because shifting 8 (binary 1000) one place right gives 4 (binary 0100). This function is part of the Engineering category and is useful for low-level bit manipulation, particularly in digital logic, data encoding, and certain mathematical operations.
What Is BITRSHIFT and Where Does It Fit?
BITRSHIFT is one of several bitwise functions in Google Sheets, alongside BITAND, BITOR, BITXOR, and BITLSHIFT. Bitwise operations treat numbers as binary (base-2) sequences of 0s and 1s. Shifting right moves each bit to a lower position; the rightmost bit falls off, and a 0 fills the leftmost position. This is equivalent to integer division by 2^shift_amount, discarding any remainder. For example, =BITRSHIFT(13, 1) returns 6, because 13 in binary is 1101, shifting right gives 0110 (6), which equals 13 ÷ 2 = 6.5, truncated to 6.
Syntax and Arguments
The syntax is BITRSHIFT(value, shift_amount). Both arguments are required.
- value – the number whose bits you want to shift. It must be an integer between -2^48 and 2^48 (approximately -281 trillion to 281 trillion).
- shift_amount – the number of places to shift right. It must be an integer between -53 and 53. A negative shift_amount shifts left (equivalent to
BITLSHIFT).
If either argument is not an integer, Google Sheets truncates it to an integer. For instance, =BITRSHIFT(8.9, 1.7) treats 8.9 as 8 and 1.7 as 1, returning 4.
How BITRSHIFT Works: A Step-by-Step Example
Let’s trace =BITRSHIFT(10, 2):
- Convert 10 to binary: 1010.
- Shift each bit two places to the right: the two rightmost bits (1 and 0) drop off, and two 0s are added on the left, giving 0010.
- Convert 0010 back to decimal: 2.
So =BITRSHIFT(10, 2) returns 2. This matches 10 ÷ 4 = 2.5, truncated to 2. For negative numbers, Google Sheets uses two’s complement representation, so shifting right preserves the sign (arithmetic shift). For example, =BITRSHIFT(-8, 1) returns -4, because -8 in binary (two’s complement) is …11111000, shifting right gives …11111100, which is -4.
When to Use BITRSHIFT in Real Work
BITRSHIFT is rarely needed in everyday spreadsheets, but it appears in specific technical contexts:
- Digital logic simulations – modeling hardware operations like dividing by powers of two in binary circuits.
- Data compression or encoding – extracting specific bits from a packed integer, e.g., reading color channels from a hex value.
- Mathematical shortcuts – performing fast integer division by powers of 2, though in a spreadsheet you could simply use
=INT(value / 2^shift). - Parsing bit flags – when a number encodes multiple boolean flags, shifting right lets you isolate a particular flag.
For most users, the equivalent formula =INT(value / 2^shift_amount) gives the same result for positive numbers, but BITRSHIFT is more explicit and handles negative numbers with sign extension correctly.
Common Errors and How to Avoid Them
Several mistakes can trigger errors or unexpected results:
- #VALUE! – occurs if either argument is non-numeric or if the arguments are not within the allowed ranges. For instance,
=BITRSHIFT(2^49, 1)returns #VALUE! because 2^49 exceeds the maximum value. - #NUM! – occurs if shift_amount is outside -53 to 53. For example,
=BITRSHIFT(1, 54)returns #NUM!. - Negative shift_amount – a negative shift_amount shifts left, which may cause overflow if the result exceeds 2^48. For example,
=BITRSHIFT(1, -53)returns #NUM! because 1 shifted left 53 places is 2^53, which exceeds the limit. - Non-integer arguments – they are silently truncated, not rounded. Many users expect rounding, so check your data.
If you get an error, verify that both arguments are integers within the documented ranges, and remember that shift_amount can be negative to shift left.
BITRSHIFT vs. BITLSHIFT and Other Bitwise Functions
BITRSHIFT is the counterpart to BITLSHIFT, which shifts bits left (equivalent to multiplying by powers of 2). While BITRSHIFT divides, BITLSHIFT multiplies. For example, =BITLSHIFT(3, 2) returns 12 (3 × 4).
Other related functions:
BITAND(value1, value2)– performs a bitwise AND.BITOR(value1, value2)– performs a bitwise OR.BITXOR(value1, value2)– performs a bitwise exclusive OR.
These functions are all in the Engineering category and are available in Google Sheets, but not in Microsoft Excel. In Excel, you would use BITRSHIFT as well (it exists in Excel 2013+), but the syntax is identical. If you’re migrating from Excel, note that Google Sheets requires the function to be typed in English; localized versions may use different names.
Practical Example: Extracting Bits from a Number
Suppose you have a number that encodes two flags in its lower two bits: bit 0 (value 1) and bit 1 (value 2). To extract the value of bit 1, you can shift right by 1 and then use BITAND with 1. Here’s a concrete layout:
With the encoded number in A2 (say 5, binary 101), put this formula in B2:
=BITAND(BITRSHIFT(A2, 1), 1)
This returns 0, because shifting 5 right by 1 gives 2 (binary 10), and AND with 1 gives 0. If the number were 6 (binary 110), the formula would return 1, indicating bit 1 is set. This pattern is common in low-level programming and can be replicated in sheets for educational or debugging purposes.
Frequently Asked Questions
What does BITRSHIFT do with negative numbers?
Google Sheets uses two’s complement representation for negative numbers, and BITRSHIFT performs an arithmetic shift, meaning the sign bit is preserved. So =BITRSHIFT(-16, 2) returns -4. This is the same behavior as in most programming languages.
Can I use BITRSHIFT with decimal numbers?
Yes, but the function truncates any decimal part of both arguments to integers before shifting. For example, =BITRSHIFT(7.9, 1.1) treats 7.9 as 7 and 1.1 as 1, returning 3. If you need rounding, use ROUND first.
Why does BITRSHIFT return #VALUE! for large numbers?
Because the value argument must be between -2^48 and 2^48. Numbers outside that range, such as 2^49, cause a #VALUE! error. This limit is set by Google Sheets to ensure accurate bitwise operations.
Is BITRSHIFT the same as dividing by 2?
For positive integers, yes, BITRSHIFT(value, 1) equals INT(value/2). For negative numbers, it also matches integer division truncating toward zero? Actually, arithmetic shift truncates toward negative infinity, so -3 shifted right by 1 gives -2, while INT(-3/2) gives -1. So they differ for negative odd numbers.
Does BITRSHIFT work in Excel?
Yes, Excel has a BITRSHIFT function with the same syntax, available in Excel 2013 and later. However, the allowed value range is slightly different (up to 2^48 as well), but the behavior is identical.
Can I shift by more than 53 places?
No, the shift_amount must be between -53 and 53. Shifting by 54 or more returns a #NUM! error. This limit is due to the 53-bit mantissa of double-precision floating-point numbers, which Google Sheets uses internally.
Related
- Google Sheets URL from Script? Get a Link in Apps Script
- Balance Charger: What It Is & How It Works
- Data Entry Jobs with No Experience: Real Answers
Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.
More in How-to basics
- How to Delete an Excel File SafelyTo delete an Excel file on Windows, close it, find it in File Explorer, select it, and press…
- Google Sheets FILTER Function: A Practical TutorialIn Google Sheets, use the FILTER function to return only the rows or columns that meet conditions. If…
- Data Entry in Computerized Method: How It WorksData entry in a computerized method means capturing information—text, numbers, dates, or codes—into a digital system using software…
- Open Excel Files Online: Your Options ExplainedYes. To open an Excel file online, sign in to Microsoft 365 or OneDrive with a Microsoft account,…
- AVERAGEIFS in Google Sheets: Criteria and ExamplesIn Google Sheets, use AVERAGEIFS to average values that meet multiple conditions. With sales in C2:C100, regions in…
- Hide a Column in a Power BI Table: Options ExplainedYes, but the right method depends on what you mean by “hide.” To remove a column from one…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.