Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * check_pow2: Returns 1 if n is power of 2
- */
- #include <stdio.h>
- #include <assert.h>
- static int check_pow2(unsigned int n) {
- return n != 0 && (n&n-1) == 0;
- }
- int main(void) {
- assert(!check_pow2(0));
- assert(check_pow2(1));
- assert(check_pow2(2));
- assert(check_pow2(1<<16));
- assert(!check_pow2((1<<16)+1));
- return 0;
- }
Add Comment
Please, Sign In to add comment