Skip to main content

java program to find the total number of set bits of the number

 java program to find the total number of set bits of the number 


Code::

import java.util.*;
class Test{
public static void main(String[] nums){
int n = 7;
int count = 0;
while(n!=0){
int bit = n&1;
if(bit==1){
count++;
}
n = n>>1;
}
System.out.println("Set Bits : "+count);
}
}
o/p: 3

Comments