The Algorithms logo
The Algorithms
AboutDonate

Is Power Two

m
package com.thealgorithms.bitmanipulation;

/**
 * Is number power of 2
 * @author Bama Charan Chhandogi (https://github.com/BamaCharanChhandogi)
 */

public class IsPowerTwo {
    public static boolean isPowerTwo(int number) {
        if (number <= 0) {
            return false;
        }
        int ans = number & (number - 1);
        return ans == 0;
    }
}