We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8f027c4 commit 39aa7a3Copy full SHA for 39aa7a3
src/me/ramswaroop/bits/RightmostSetBit.java
@@ -0,0 +1,32 @@
1
+package me.ramswaroop.bits;
2
+
3
+/**
4
+ * Created by IntelliJ IDEA.
5
+ *
6
+ * @author: ramswaroop
7
+ * @date: 6/3/15
8
+ * @time: 11:56 PM
9
+ */
10
+public class RightmostSetBit {
11
12
+ public static int getRightmostSetBitPosition(long n) {
13
+ int position = 0;
14
+ while (n > 0) {
15
+ position++;
16
+ if ((n & 1) == 1) {
17
+ break;
18
+ }
19
+ n >>= 1;
20
21
+ return position;
22
23
24
+ public static void main(String a[]) {
25
+ System.out.println(getRightmostSetBitPosition(0));
26
+ System.out.println(getRightmostSetBitPosition(1));
27
+ System.out.println(getRightmostSetBitPosition(2));
28
+ System.out.println(getRightmostSetBitPosition(5));
29
+ System.out.println(getRightmostSetBitPosition(18));
30
+ System.out.println(getRightmostSetBitPosition(19));
31
32
+}
0 commit comments