File tree Expand file tree Collapse file tree 1 file changed +18
-4
lines changed
src/main/java/com/thealgorithms/bitmanipulation Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change 11package com .thealgorithms .bitmanipulation ;
22
33/**
4- * Find The Index Of Right Most SetBit
5- * @author Bama Charan Chhandogi (https://github.com/BamaCharanChhandogi)
4+ * Utility class for bit manipulation operations.
5+ * This class provides methods to work with bitwise operations.
6+ * Specifically, it includes a method to find the index of the rightmost set bit
7+ * in an integer.
8+ * This class is not meant to be instantiated.
9+ *
10+ * Author: Bama Charan Chhandogi (https://github.com/BamaCharanChhandogi)
611 */
7-
812public final class IndexOfRightMostSetBit {
13+
914 private IndexOfRightMostSetBit () {
1015 }
16+
17+ /**
18+ * Finds the index of the rightmost set bit in the given integer.
19+ * The index is zero-based, meaning the rightmost bit has an index of 0.
20+ *
21+ * @param n the integer to check for the rightmost set bit
22+ * @return the index of the rightmost set bit; -1 if there are no set bits
23+ * (i.e., the input integer is 0)
24+ */
1125 public static int indexOfRightMostSetBit (int n ) {
1226 if (n == 0 ) {
1327 return -1 ; // No set bits
@@ -16,7 +30,7 @@ public static int indexOfRightMostSetBit(int n) {
1630 // Handle negative numbers by finding the two's complement
1731 if (n < 0 ) {
1832 n = -n ;
19- n = n & (~n + 1 ); // Get the rightmost set bit in positive form
33+ n = n & (~n + 1 ); // Isolate the rightmost set bit
2034 }
2135
2236 int index = 0 ;
You can’t perform that action at this time.
0 commit comments