Writing numbers as Java floats

Please bear with me as I am *extremely *new to this. I am doing homework on Java Primitive Data Types and Base Conversion. The question is:

1. Write the following numbers as Java *floats*, convert the Java word to hexadecimala. 176.2058

b. -132.456

I've been searching for hours on how to have this dumbed down for me and everything I read makes it terribly confusing. I understand converting binaries to hexadecimal but I can't, for the life of me, seem to understand *how* to write the numbers as Java floats. The whole 'excess-27' thing is throwing me completely off and I don't even know how to approach this anymore. Please, if someone could explain this to me in the dumbest way possible (I'm serious, like you're explaining it to your mom or even your grandmother), I would oh-so greatly appreciate it. I'm not looking for a response that just has the answer. I honestly want and need to know how to do this. Thank you!

Re: Writing numbers as Java floats

Understanding IEEE 754 floating-point specification requires some time and effort. You should read your textbook or lecture notes, or at least Wikipedia pages about floating point and single-precision floating-point format. The fact that Java implements IEEE 754 as well as parameters of single-precision floating-point (the size of the significand and exponent) are stated in the Oracle documentation.

First you need to convert 176.2058 to binary: 10110000.00110100101011110100111100001100..._{2}. Next you round it to 24 bits: 10110000.0011010010101111. In the final representation, the decimal point should be after the first bit: 1.01100000011010010101111 * 2^{7}. The exponent is stored as the sum of 7 (or whatever it is for a given number) and 127, i.e., 134 in this case. In binary, 134 = 10000110_{2}. The first bit of significand is always 1, so it is not recorded, which leaves 23 bits. The final representation consists of the sign bit (0 means +1), the exponent and the significand. Thus, it is

0 10000110 01100000011010010101111.

Here are a couple of online calculators that can compute floating-point representation.

2 Attachment(s)

Re: Writing numbers as Java floats

Hi,

Emakarov has given you a good answer. The only thing he left out is the binary representation of reals; e.g. 101.1101 and how to get such. The following attachment gives a method to do this. However, I think it's almost impossible to do by hand. The calculators suggested by emakarov are good.

Attachment 29125

Attachment 29127