Bitoperation Hacks

Various bit operation hacks

Examples:

  • Compute the minimum (min) or maximum (max) of two integers without branching
  • Determining if an integer is a power of 2
  • Reverse the bits in a byte with 3 operations (64-bit multiply and modulus division):

http://graphics.stanford.edu/~seander/bithacks.html#OperationCounting

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License