public class SetBits {
public static void main(String[] args) {
// how to find number of set bits in Decimal number
// means number of 1's present in decimal number
int num = 5 ;
int count = 0;
// 8 bits representation of 5 : 00001001
while(num>0) {
if((num & 1) == 1) {
count++;
}
num=num>>1;
}
System.out.println(count);
}
}
Output : 2
Youtube video link:
https://youtu.be/Jh9i1OLLfks