BITRSHIFT function
Shifts the bits of a number to the right by a given amount, which divides it by a power of 2 and drops the remainder.
Available in Excel 2013 and later, Microsoft 365, Excel for the web, Excel for Mac 2016 and later
Excel 2013 and laterWorks in Google Sheets
Syntax
BITRSHIFT(number, shift_amount)| Argument | What it means | |
|---|---|---|
number | Required | A whole number from 0 to 2^48 − 1. |
shift_amount | Required | How many positions to move the bits to the right. A negative value shifts left instead. Must be between -53 and 53. |
Returns: A decimal number: number divided by 2^shift_amount, rounded down.
How BITRSHIFT works
BITRSHIFT moves every bit of a number to the right; the bits that fall off the end are thrown away. Shifting right by k places is the same as dividing by 2^k and discarding the remainder, so BITRSHIFT(13, 2) is INT(13/4) = 3.
Its most common job is unpacking values that were stored together. A colour in Excel's Color property, for example, holds blue in the top byte, green in the middle byte and red in the bottom byte; shift right by 8 and mask with BITAND 255 to pull out the green value. A negative shift_amount shifts left like BITLSHIFT. Inputs must be whole numbers from 0 to 2^48 − 1.
Examples
1Shift right by 2
| A | B | C | |
|---|---|---|---|
| 1 | Number | Shift | |
| 2 | 13 | 2 | 3 |
Result: 3
13 is 1101. Moving it two places right drops the last two bits (01) and leaves 11, which is 3.
2Extract the green value from a colour number
| A | B | |
|---|---|---|
| 1 | Colour value | |
| 2 | 16748574 | 144 |
Result: 144
16748574 is the colour number Excel stores for RGB(30, 144, 255) (red + green×256 + blue×65536). Shifting right 8 bits removes the red byte; BITAND with 255 then keeps only the green byte: 144.
Common errors and how to fix them
| Error | Why it happens | Fix |
|---|---|---|
#NUM! | The number is negative, not whole, at least 2^48, or |shift_amount| is more than 53. | Use whole numbers in range; use INT with division for larger values. |
#VALUE! | An argument is non-numeric text. | Convert with VALUE. |
Tips
BITRSHIFT(n, k)gives the same answer asINT(n/2^k)for valid inputs.- Combine shift and mask to read any field:
=BITAND(BITRSHIFT(value, start_bit), 2^width-1).
Google Sheets
BITRSHIFT also exists in Google Sheets and works the same way for everyday use, so the examples above work there too.
BITRSHIFT in other languages
In a non-English version of Excel the function has a local name. Excel translates formulas automatically when a file is opened in another language.
| Language | Function name |
|---|---|
| Danish | BITRSKIFT |
| Dutch | BIT.VERSCHUIF.RECHTS |
| Finnish | BITTI.SIIRTO.O |
| French | BITDECALD |
| German | BITRVERSCHIEB |
| Hungarian | BIT.JOBB.ELTOL |
| Italian | BIT.SPOSTA.DX |
| Norwegian (Bokmål) | BITHFORSKYV |
| Polish | BIT.PRZESUNIĘCIE.W.PRAWO |
| Portuguese (Brazil) | DESLOCDIRBIT |
| Portuguese (Portugal) | BITDESL.DIR |
| Russian | БИТ.СДВИГП |
| Spanish | BIT.DESPLDCHA |
| Swedish | BITHSKIFT |
| Turkish | BİTSAĞAKAYDIR |