mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-07 17:56:02 +08:00
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:

committed by
GitHub

parent
68fdec5977
commit
b61faf4ede
@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user