mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-24 13:10:13 +08:00

* 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>
17 lines
365 B
Java
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;
|
|
}
|
|
}
|