For example, I have the number 0.1
:
double n = 0.1;
It's represented in IEEE-754 big endian as:
0 01111111011 1001100110011001100110011001100110011001100110011010
How can I output 0.1
in this binary format?
This allows the way that the bits are allocated to vary so that both very large and very small numbers can be represented. Binary floating point numbers are expressed in the form mantissa × 2, start superscript, e, x, p, o, n, e, n, t, end superscript,2exponent, e.g. 0, point, 101,0.101 x 2, to the power 4 ,24.
A Floating Point number usually has a decimal point. This means that 0, 3.14, 6.5, and -125.5 are Floating Point numbers. Since Floating Point numbers represent a wide variety of numbers their precision varies.
To convert integer to binary, start with the integer in question and divide it by 2 keeping notice of the quotient and the remainder. Continue dividing the quotient by 2 until you get a quotient of zero. Then just write out the remainders in the reverse order.
In the 32 bit IEEE format, 1 bit is allocated as the sign bit, the next 8 bits are allocated as the exponent field, and the last 23 bits are the fractional parts of the normalized number. A sign bit of 0 indicates a positive number, and a 1 is negative.
Float class can do that for you calling the method Float.floatToIntBits
final int intBits = Float.floatToIntBits(4.1f);
final String binary = Integer.toBinaryString(intBits);
System.out.println(binary);
here can you verify setting the fusses i the binary result...
https://www.h-schmidt.net/FloatConverter/IEEE754.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With