You may try the method using this test case:
public static boolean twoPowerN(int x){
return ((x & -x) == x) ? true : false;
}
System.out.println(twoPowerN((int) Math.pow(2, 8)));
Basically it returns true for all integers 2powN, for example 2^100 or 2^7 or 2^33. A false will be returned for values other than 2powN. Well, that's the purpose of this method anyway (to check if a method is 2 to the power of N), right? :)
Have a good day everyone!
0 comments:
Post a Comment