带有示例的Java lang.Long.toBinaryString()方法
java.lang.Long.toBinaryString()方法返回long参数的字符串表示形式,为基数2中的无符号整数。
示例
以下是实现toBinaryString()方法的示例-
import java.lang.*;
public class Demo {
public static void main(String[] args) {
long l = 190;
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 is " + Long.toBinaryString(l));
//返回一位数
System.out.println("Number of one bits = "
}
}输出结果
Number = 190 Binary is 10111110 Number of one bits = 6
示例
让我们看看另一个考虑负数的例子-
import java.lang.*;
public class Demo {
public static void main(String[] args) {
long l = -25;
System.out.println("Number = " + l);
System.out.println("Binary is " + Long.toBinaryString(l));
System.out.println("Number of one bits = " + Long.bitCount(l));
}
}输出结果
Number = -25 Binary is 1111111111111111111111111111111111111111111111111111111111100111 Number of one bits = 62
热门推荐
10 读书祝福语女生短句简短
11 感谢同事新婚祝福语简短
12 感谢教官文案祝福语简短
13 员工聚会蛋糕祝福语简短
14 元宵发客户祝福语简短
15 给团队信心祝福语简短
16 医美的祝福语大全简短
17 异国姻缘的祝福语简短
18 兄妹拍照祝福语简短的话