How can I get single bits (or an entire variable) of a double or a float?
For example if I have
float a = 0.5;
I would expect a String equal to:
"00111111000000000000000000000000"
or in hex:
"F000000"
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For Java, a float is on 32 bits like a
int, and a double is on 64 bits like along. Finding the binary representation of these numbers, you need to:You can check that it works by doing the reverse operation:
For the hexadecimal representation, you can use respectively
Integer.parseInt("...", 16);andLong.parseLong("...", 16);