Results 1 to 3 of 3
Like Tree2Thanks
  • 1 Post By emakarov
  • 1 Post By johng

Math Help - Writing numbers as Java floats

  1. #1
    Newbie
    Joined
    Sep 2013
    From
    North Carolina
    Posts
    1

    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 hexadecimal
    a. 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!
    Follow Math Help Forum on Facebook and Google+

  2. #2
    MHF Contributor
    Joined
    Oct 2009
    Posts
    5,417
    Thanks
    718

    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 * 27. 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 = 100001102. 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.
    Thanks from johng
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Super Member
    Joined
    Dec 2012
    From
    Athens, OH, USA
    Posts
    538
    Thanks
    217

    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.

    Writing numbers as Java floats-mhfdiscretemath2a.png

    Writing numbers as Java floats-mhfdiscretemath2b.png
    Thanks from emakarov
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Writing the sum of two square numbers?
    Posted in the Math Topics Forum
    Replies: 1
    Last Post: March 13th 2011, 03:27 PM
  2. Writing a number in terms of other numbers.
    Posted in the Algebra Forum
    Replies: 1
    Last Post: March 15th 2010, 07:31 PM
  3. Writing numbers as sum of primes
    Posted in the Number Theory Forum
    Replies: 16
    Last Post: December 21st 2009, 12:16 PM
  4. Writing the Numbers till N to form a new number
    Posted in the Number Theory Forum
    Replies: 1
    Last Post: March 25th 2009, 01:17 AM
  5. Writing complex numbers in the form x+ij.
    Posted in the Calculus Forum
    Replies: 2
    Last Post: December 6th 2008, 05:04 AM

Search Tags


/mathhelpforum @mathhelpforum