Skip to content

Instantly share code, notes, and snippets.

@xypaul
Created June 24, 2015 00:58
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 xypaul/4701837c4360c1012781 to your computer and use it in GitHub Desktop.
Save xypaul/4701837c4360c1012781 to your computer and use it in GitHub Desktop.
Power of 2 - recursive and bitwise :)
public static Boolean powerCheck(int a) {
return a!=0 && (a & a-1) == 0;
}
public static Boolean recursivePowerCheck(int a){
if (a == 1) return true;
if (a == 0 || a % 2 != 0) return false;
return recursivePowerCheck(a/2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment