We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d402115 commit 2ab3f9dCopy full SHA for 2ab3f9d
src/main/java/com/thealgorithms/bitmanipulation/LowestSetBit.java
@@ -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
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