带有示例的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
热门推荐
1 带狗狗训练
4 听力训练狗狗
6 怎训练狗狗
7 腹肌训练狗狗
8 网球训练狗狗
9 记叙文训练狗狗
10 狗狗太凶怎么训练
11 核心力量训练狗狗
12 狗狗乱叫怎么训练
13 发音训练狗狗
14 怎么训练狗狗叼东西给主人
15 荆州训练狗狗
16 篮球训练狗狗
17 做训练狗狗
18 训练狗狗坐姿