Skip to content

Commit 2ab3f9d

Browse files
Updated the code after reviewing with CI checks
1 parent d402115 commit 2ab3f9d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.thealgorithms.bitmanipulation;
2+
3+
public final class LowestSetBit {
4+
5+
/**
6+
* Method to isolate the lowest set bit of a given integer.
7+
* @param n the integer input
8+
* @return the isolated lowest set bit or 0 if n is 0
9+
*/
10+
public int isolateLowestSetBit(int n) {
11+
return n & -n; // Works for both positive and negative
12+
}
13+
14+
/**
15+
* Method to clear the lowest set bit of a given integer.
16+
* @param n the integer input
17+
* @return the integer with the lowest set bit cleared
18+
*/
19+
public int clearLowestSetBit(int n) {
20+
return n & (n - 1);
21+
}
22+
}

0 commit comments

Comments
 (0)