File tree Expand file tree Collapse file tree 2 files changed +4
-7
lines changed
main/java/com/thealgorithms/bitmanipulation
test/java/com/thealgorithms/bitmanipulation Expand file tree Collapse file tree 2 files changed +4
-7
lines changed Original file line number Diff line number Diff line change @@ -14,17 +14,17 @@ public final static Optional<Integer> findHighestSetBit(int num) {
14
14
if (num < 0 ) {
15
15
throw new IllegalArgumentException ("Input cannot be negative" );
16
16
}
17
-
17
+
18
18
if (num == 0 ) {
19
19
return Optional .empty ();
20
20
}
21
-
21
+
22
22
int position = 0 ;
23
23
while (num > 0 ) {
24
24
num >>= 1 ;
25
25
position ++;
26
26
}
27
-
27
+
28
28
return Optional .of (position - 1 );
29
29
}
30
30
}
Original file line number Diff line number Diff line change @@ -16,9 +16,6 @@ void testHighestSetBit() {
16
16
assertEquals (5 , HighestSetBit .findHighestSetBit (37 ).orElse (-1 ));
17
17
assertFalse (HighestSetBit .findHighestSetBit (0 ).isPresent ());
18
18
assertEquals (0 , HighestSetBit .findHighestSetBit (1 ).orElse (-1 ));
19
-
20
- // Use assertThrows with a specific exception type and provide a lambda
21
19
assertThrows (IllegalArgumentException .class , () -> HighestSetBit .findHighestSetBit (-37 ).orElse (-1 ));
22
20
}
23
- }
24
-
21
+ }
You can’t perform that action at this time.
0 commit comments