sparkfun/MMA8452_Accelerometer — pull request #5 by BruceFletcher (2013-09-24 07:17:58+00:00)
Title: 32-bit support, redundant code removal

This change makes the basic MMA8452 example work properly on 32-bit boards. Tested on a Teensy 3 and confirmed to still work on an ATmega328-based Arduino clone.

Also removed a double negation of gCount:

gCount = ~gCount + 1; // bitwise negation of gCount
gCount *= -1; // arithmetic negation of gCount

So why does the code work anyway? Because in C a right-shift on a signed integer is an arithmetic shift, meaning it handles negative numbers the way you would want for gCount in this application; (-4 >> 1) == -2.