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 it
The result of 16 shifted right by 2 positions. Select a bit to change it. Change the bit width or the signed mode to see the effect.
Name or expression
ID0
ASCII
·
Binary
0b
0b00000100
Hex
0x
0x04
Decimal
4
Shift
Name or expression
ID0
Binary
0b
Hex
0x
Decimal
ASCII
·
Shift
Sign
Bits
Endian
7
6
5
4
3
2
1
0
Worked example
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.
Where this 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.
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 tool
The full editor holds many values at the same time. It also evaluates expressions across them, and it reads live values from a serial port.
Open the full editorQuestions
- 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.