本文介绍了双转换为二进制重新presentation?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题,所以我尝试了双转换成其二进制重新presentation,但使用这种 Long.toBinaryString(Double.doubleToRawLongBits(D))没有帮助,因为我有大的数字,那么久不能存储他们即 2 ^ 900

I have the following problem, so I tried to convert a double to its binary representation, but using this Long.toBinaryString(Double.doubleToRawLongBits(d)) doesn't help, since I have large numbers, that Long can't store them i.e 2^900.

鸭preciate任何帮助:)

Appreciate any help :).

推荐答案

Long.toBinaryString(Double.doubleToRawLongBits(D))似乎工作就好了。

System.out.println("0:                0b" + Long.toBinaryString(Double.doubleToRawLongBits(0D)));
System.out.println("1:                0b" + Long.toBinaryString(Double.doubleToRawLongBits(1D)));
System.out.println("2:                0b" + Long.toBinaryString(Double.doubleToRawLongBits(2D)));
System.out.println("2^900:            0b" + Long.toBinaryString(Double.doubleToRawLongBits(Math.pow(2, 900))));
System.out.println("Double.MAX_VALUE: 0b" + Long.toBinaryString(Double.doubleToRawLongBits(Double.MAX_VALUE)));

/*
    prints:
    0:                0b0
    1:                0b11111111110000000000000000000000000000000000000000000000000000
    2:                0b100000000000000000000000000000000000000000000000000000000000000
    2^900:            0b111100000110000000000000000000000000000000000000000000000000000
    Double.MAX_VALUE: 0b111111111101111111111111111111111111111111111111111111111111111
*/

这篇关于双转换为二进制重新presentation?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 08:16