java.lang.Long.bitCount()%uA0方法返回一个位在指定long值i的二进制补码表示的数。这个函数有时被称为“人口数”。
声明
以下是java.lang.Long.bitCount()方法的声明
public static int bitCount(long i)
参数
-
i%uA0-- 这是一个long值。
返回值
此方法返回一个位在指定long值的二进制补码表示的数。
异常
-
NA
例子
下面的例子显示java.lang.Long.bitCount()方法的使用。
package com.yiibai 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