Files
Bama Charan Chhandogi b61faf4ede Is power two algo added. (#4321)
* is power two algo added

* Linter solved

* Update src/main/java/com/thealgorithms/bitmanipulation/IsPowerTwo.java

* Update src/test/java/com/thealgorithms/bitmanipulation/IsPowerTwoTest.java

---------

Co-authored-by: BamaCharanChhandogi <b.c.chhandogi@gmailcom>
Co-authored-by: Debasish Biswas <debasishbsws.dev@gmail.com>
2023-08-18 12:53:09 +00:00

17 lines
365 B
Java

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;
}
}