How to turn Double into Binario Java

Asked

Viewed 102 times

1

I tried to do the method of turning the result of a calculation like this ->

public String converteResultado(String resultado) {  
    return String.valueOf(Double.doubleToLongBits(Double.valueOf(resultado)));
}

The result is Decimal numbers, ex:(1.1 or 0.12), I thought of turning the result String into Double, then turning Double into Binario, and then turning Binario into String, and then returning the result into String, OBS: I have to return a result in String.

  • a look at this link, it’s in Spanish, but it’s understandable: https://es.stackoverflow.com/questions/32796/c%C3%B3mo-pasar-de-decimal-a-binario-en-java

1 answer

0

I did the following test and it worked well

String i =  Long.toBinaryString(Double.doubleToRawLongBits(1.1D));
System.out.println(i);

returned 11111111110001100110011001100110011001100110011001100110011010

Browser other questions tagged

You are not signed in. Login or sign up in order to post.