static int bitCount(long i)
描述 (Description)
java.lang.Long.bitCount()方法返回指定long值i二进制补码二进制表示中的一位数。 此功能有时称为population count.
声明 (Declaration)
以下是java.lang.Long.bitCount()方法的声明public static int bitCount(long i)
参数 (Parameters)
i - 这是很长的价值。
返回值 (Return Value)
此方法返回指定long值的二进制补码表示形式中的一位数。
异常 (Exception)
NA
例子 (Example)
以下示例显示了java.lang.Long.bitCount()方法的用法。package com.iowiki;
import java.lang.*;
public class LongDemo {
public static void main(String[] args) {
long l = 219;
System.out.println("Number = " + l);
/* returns the string representation of the unsigned long value
represented by the argument in binary (base 2) */
System.out.println("Binary = " + Long.toBinaryString(l));
// returns the number of one-bits
System.out.println("Number of one bits = " + Long.bitCount(l));
}
}
让我们编译并运行上面的程序,这将产生以下结果 -Number = 219
Binary = 11011011
Number of one bits = 6