Java Integer bitCount()方法
java.lang.Integer.bitCount()方法返回指定int值的二进制补码二进制表示形式中的一位数。
首先,设置一个int值-
int val = 210;
现在,找到一位的数量-
Integer.bitCount(val)
以下是在Java中实现bitCount()方法的示例-
示例
public class Main {
public static void main(String[] args) {
int val = 210;
System.out.println("Number = " + val);
System.out.println("Binary = " + Integer.toBinaryString(val));
// returns the number of one-bits
System.out.println("Number of one bits = " + Integer.bitCount(val));
}
}输出结果
Number = 210 Binary = 11010010 Number of one bits = 4
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短