File tree 2 files changed +18
-5
lines changed
main/java/com/thealgorithms/bitmanipulation
test/java/com/thealgorithms/bitmanipulation
2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change 1
1
package com .thealgorithms .bitmanipulation ;
2
2
3
- public class LowestSetBit {
3
+ /**
4
+ * Lowest Set Bit
5
+ * @author Prayas Kumar (https://github.com/prayas7102)
6
+ */
4
7
8
+ public class LowestSetBit {
9
+ // Private constructor to hide the default public one
10
+ private LowestSetBit () {
11
+ }
5
12
/**
6
- * Isolates the lowest set bit of the given number. For example, if n = 18 (binary: 10010),
7
- * the result will be 2 (binary: 00010).
13
+ * Isolates the lowest set bit of the given number. For example, if n = 18
14
+ * (binary: 10010), the result will be 2 (binary: 00010).
8
15
*
9
16
* @param n the number whose lowest set bit will be isolated
10
17
* @return the isolated lowest set bit of n
11
18
*/
12
19
public static int isolateLowestSetBit (int n ) {
20
+ // Isolate the lowest set bit using n & -n
13
21
return n & -n ;
14
22
}
15
- }
23
+ }
Original file line number Diff line number Diff line change 4
4
5
5
import org .junit .jupiter .api .Test ;
6
6
7
+ /**
8
+ * Test case for Lowest Set Bit
9
+ * @author Prayas Kumar (https://github.com/prayas7102)
10
+ */
11
+
7
12
public class LowestSetBitTest {
8
13
9
14
@ Test
@@ -47,4 +52,4 @@ void testLowestSetBitWithLargeNumber() {
47
52
// Test with a large number
48
53
assertEquals (64 , LowestSetBit .isolateLowestSetBit (448 )); // 448 in binary: 111000000, lowest bit is 64
49
54
}
50
- }
55
+ }
You can’t perform that action at this time.
0 commit comments