Created
November 26, 2014 15:01
-
-
Save Neill3d/63ff88fff5f60d7e60c9 to your computer and use it in GitHub Desktop.
nice code example for checking if value is power of two
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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