Skip to content

Commit dc2acb7

Browse files
Create NoOfOneBits.java
1 parent caaee56 commit dc2acb7

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

Bit Manipulation/NoOfOneBits.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class NoOfOneBits {
2+
public int hammingWeight(int n) {
3+
int setBits = 0;
4+
while(n!=1){
5+
if(n%2 == 1){
6+
setBits += 1;
7+
}
8+
n = n/2;
9+
}
10+
11+
return setBits+1;
12+
}
13+
}

0 commit comments

Comments
 (0)