0
点赞
收藏
分享

微信扫一扫

Give a very good method to count the number of ones in a


Give a very good method to count the number of ones in a "n" (e.g. 32) bit number.

 

public class Count {
public static void main(String args[])
{
int count=0;
int num=1101011011;
for(int i=0;i<6;i++)//统计的位数
{
if(num%Math.pow(10,i+1)==Math.pow(10,i))
count++;
num=(int) (num-num%Math.pow(10,i+1));

}

System.out.print(count);

}

}

 

举报

相关推荐

0 条评论