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>
This commit is contained in:
Bama Charan Chhandogi
2023-08-18 18:23:09 +05:30
committed by GitHub
parent 68fdec5977
commit b61faf4ede
2 changed files with 50 additions and 0 deletions

View File

@ -0,0 +1,16 @@
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;
}
}