6

What does >>= do in this example?

byte fsr = 2;
fsr >>= 2; 

I came across it here: https://github.com/sparkfun/MMA8452_Accelerometer/blob/master/Firmware/MMA8452Q_BasicExample/MMA8452Q_BasicExample.ino

  • 2
    Same concept as `+=`. – Blorgbeard May 23 '13 at 01:45
  • StackOverflow has a better search engine than Google, so you can search for the token directly (in quotes): http://stackoverflow.com/search?q=%22%3E%3E=%22 – 1'' May 23 '13 at 01:50
  • You may also use your common sense (if any) to search for a [slightly broader category](http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B). –  May 23 '13 at 02:10
  • Does this answer your question? [What does <<= operator mean in Java?](https://stackoverflow.com/questions/12071826/what-does-operator-mean-in-java) – Zoe Sep 24 '20 at 14:36

2 Answers2

11

It does this:

fsr = fsr >> 2;
gzm0
  • 14,752
  • 1
  • 36
  • 64
2
fsr >>= 2;

is

fsr = fsr >> 2;

In Bitwise Context, two bit places to the right is being shifted.

In Arithmetic context, the number in fsr is being divided by 2^2(4);

Barath Ravikumar
  • 5,658
  • 3
  • 23
  • 39