Skip to content

Commit d402115

Browse files
Code for LowestSetBitManipulation added
1 parent 87871ef commit d402115

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
public class LowestSetBit {
2+
3+
// Method to isolate the lowest set bit
4+
public int isolateLowestSetBit(int n) {
5+
if (n == 0) return 0; // Special case for 0
6+
return n & -n;
7+
}
8+
9+
// Method to clear the lowest set bit
10+
public int clearLowestSetBit(int n) {
11+
return n & (n - 1);
12+
}
13+
}

0 commit comments

Comments
 (0)