Beetwise

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:

  1. Write the value: 00010000.
  2. Move every bit two positions to the right.
  3. Fill the two high positions with 0.
  4. The result is 00000100, which is 4.

The value 200 shifted right

The value 200 shifted right
ExpressionBinaryDecimal
200 >> 011001000200
200 >> 101100100100
200 >> 20011001050
200 >> 30001100125
200 >> 40000110012
200 >> 5000001106
200 >> 6000000113
200 >> 7000000011

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 editor

Questions 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.