It's a little known fact that >> in C++ (and I suspect in C as well) on a signed type is not guaranteed to be an arithmetical shift. It's up to the implementation and most implementation choose arithmetical shift for signed and logical shift for unsigned but this does not mean that <i>all</i> the implementations do this.
So some of this tricks are contingent on the particular implementation specific behavior.
An oldie but a goodie.<p>Mandatory warning: please don't use those unless you really know what you're doing. Most modern CPUs have instructions for computing all of that stuff and the compiler will try to use them. Those clever hacks might actually hurt both readability and performance if they're misused.<p>Typically on PC architectures (and even on most modern embedded systems) you shouldn't have to use those hacks.
On a similar note:<p><a href="http://www.amazon.com/gp/product/0321842685/ref=s9_simh_gw_p14_d0_i1?pf_rd_m=ATVPDKIKX0DER&pf_rd_s=center-2&pf_rd_r=1QMBXBDPHW9X6ZJ1KDN9&pf_rd_t=101&pf_rd_p=1389517282&pf_rd_i=507846" rel="nofollow">http://www.amazon.com/gp/product/0321842685/ref=s9_simh_gw_p...</a>
I think the real value of these hacks is to <i>understand how and they work</i> rather than the possible efficiency gains they may give. Sure, sometimes you just <i>have to</i> get the gains, but these days, on modern platforms this is hardly ever the case.<p>But man, if you <i>think</i> you know how to deal with the binary and bitwise operations, please take some time to go through all of the hacks and examine how they work. It's quite possible you learn something new and interesting, which may have surprising applications elsewhere.