Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to see number representation in floating point binary

Tags:

java

c++

binary

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?

like image 527
Max Koretskyi Avatar asked Oct 05 '16 08:10

Max Koretskyi


People also ask

How do you represent a floating-point number in binary?

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.

How do you read a floating-point number?

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.

How do you find the representation of a binary number?

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.

How do you represent in floating point format?

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.


1 Answers

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

like image 141
ΦXocę 웃 Пepeúpa ツ Avatar answered Oct 20 '22 18:10

ΦXocę 웃 Пepeúpa ツ