When I was optimizing a piece of C++ code, I noticed a very odd behavior of C++ programs in handling shiftings, that right shifting a negative integer to its least significant 1 will result a -1.
e.g.
This bit hacking techinique could be beneficial in optimizing some C++ programs. For example, here is a simple comparison between two integers, it conducts as following
The generic approach is equivalent with the following piece of code, but shows a better performance