Skip to content

Instantly share code, notes, and snippets.

@Neill3d
Created November 26, 2014 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Neill3d/63ff88fff5f60d7e60c9 to your computer and use it in GitHub Desktop.
Save Neill3d/63ff88fff5f60d7e60c9 to your computer and use it in GitHub Desktop.
nice code example for checking if value is power of two
/**
* @fn IsPowerOfTwo(int n)
* @brief Returns true if /param n is an integer power of 2.
*
* Taken from Steve Baker's Cute Code Collection.
* http://www.sjbaker.org/steve/software/cute_code.html
*/
static bool IsPowerOfTwo(int n) { return ((n&(n-1))==0); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment