Skip to content

Commit d4e875e

Browse files
authored
Create Right_Most_different_bit.cpp
1 parent 31c498a commit d4e875e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Bits/Right_Most_different_bit.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution
2+
{
3+
public:
4+
//Function to find the first position with different bits.
5+
int getRightMostsetbit(int m,int n)
6+
{
7+
int res=m^n;
8+
9+
10+
if(res==0)
11+
{
12+
return -1;
13+
}
14+
15+
return log2(res & -res)+1;
16+
}
17+
18+
int posOfRightMostDiffBit(int m, int n)
19+
{
20+
21+
return getRightMostsetbit(m,n);
22+
}
23+
};

0 commit comments

Comments
 (0)