Right shift
A right shift moves every bit to a lower position.
A shift of one position divides the value by 2.
The register drops the bits that move past position 0.
Try the right shift in the bit editor
The result of 16 shifted right by 2 positions. Edit the expression or select a bit to flip it.
7
6
5
4
3
2
1
0
4
value · 8 bits · unsigned
- hex
- 0x04
Bit width
Shift
The right shift step by step
Shift 16 right by two positions:
- Write the value: 00010000.
- Move every bit two positions to the right.
- Fill the two high positions with 0.
- The result is 00000100, which is 4.
The value 200 shifted right
| Expression | Binary | Decimal |
|---|---|---|
| 200 >> 0 | 11001000 | 200 |
| 200 >> 1 | 01100100 | 100 |
| 200 >> 2 | 00110010 | 50 |
| 200 >> 3 | 00011001 | 25 |
| 200 >> 4 | 00001100 | 12 |
| 200 >> 5 | 00000110 | 6 |
| 200 >> 6 | 00000011 | 3 |
| 200 >> 7 | 00000001 | 1 |
Where the right shift is used
A right shift extracts a field after an AND with a mask.
A driver shifts a register value down to read a field that does not start at bit 0.
A right shift replaces a division by a power of two.
The right shift: points to note
- A right shift of a signed negative value is not the same in every language. An arithmetic shift copies the top bit, a logical shift fills with 0.
- A division by two rounds towards zero for a positive value. For a negative value an arithmetic shift rounds away from zero.
- The register drops the low bits. A shift back gives a different value.
The full bit editor
The full editor holds many values, evaluates expressions across them, and reads live values from a serial port.
Open this value in the full editorQuestions about the right shift
- What is 16 shifted right by 2?
- The result is 4. The set bit moves from position 4 to position 2.
- What is an arithmetic right shift?
- An arithmetic right shift copies the top bit into the new high positions, which keeps a negative value negative.
- Is a right shift the same as a division?
- For an unsigned value, yes. For a negative signed value the result rounds in a different direction.