converting double to binary in java [duplicate]

大城市里の小女人 提交于 2019-12-19 04:14:31

问题


I am generating sequence of numbers of type double like 0.9913963644564902 0.0341175990344773 0.13181105852355268 0.45773616980747556 and I have to convert it to binary representation in java.


回答1:


This will help you. I have tried out using one of your input double value - 0.9913963644564902

 public static void main(String[] args){
        double d = 0.9913963644564902;
        System.out.println("0b"+Long.toBinaryString(Double.doubleToRawLongBits(d)));
    }

The output would be

run:
0b11111111101111101110011000010011011110010101101101100001110011
BUILD SUCCESSFUL (total time: 0 seconds)


来源:https://stackoverflow.com/questions/20730179/converting-double-to-binary-in-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!