IEEE 754 32bit floating point value.


Closed Thread
Results 1 to 10 of 10

Hybrid View

  1. #1
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    968


    Did you find this post helpful? Yes | No

    Default

    I have worked on the floating point library for the 8051. This is a converter I wrote in QuickBasic 4.5 to convert a floating number entered on the PC to floating point representation that can be understood by the micro controller. See if it will help you move ahead in your quest.

    To the best of my recollection, the format is
    8 bits biased exponent followed by 24 bits signed mantissa.

    The idea is to move the mantissa till you get a 1 bit in the highest position of the mantissa and accordingly change the exponent by the amount you moved the mantissa. Then remove the highest bit (it is implicit) and put in the sign bit for the mantissa. A 1 bit here means it is a negative number.

    That's all I can offer right now. I am a bit hazy on the details at the moment as it has been more than 10 years ago that I did this. If you need any help, let me know and I'll try to help.



    Code:
    DIM Mant AS SINGLE, Expo AS INTEGER
    DIM bits AS INTEGER, Sign AS INTEGER
    
    PRINT "CFLT converter for text to float51 format"
    INPUT "Please enter the number : ", num
    
    IF num < 0 THEN
      Sign = 1
      num = -num
    END IF
    
    Mant = num
    Expo = &H80 + 24
    FOR bits = 1 TO 24
      IF (Mant AND &H800000) THEN EXIT FOR
      Mant = Mant * 2
      Expo = Expo - 1
    NEXT
    
    'remove the MSB if +ve
    IF Sign = 0 THEN
      Mant = Mant AND &H7FFFFF
    END IF
    
    PRINT "The floating point representation is  Exp, Mantissa"
    PRINT HEX$(Expo); ", "; HEX$(Mant)

  2. #2
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    Adding to the confusion to try and shead some light. You say the number you get back could be 751, which would equal 75.1. how is this sent? is it :
    00000001 01110111, or is it
    00000111 01010001?

    The first being stright binary and the second being packed BCD I will assume the first. Now when you say you need a 32 bit, floating point answer, seems to me there must be some format to this. for instance, does the device you are sending it to expect the decimal to be in any special place? is it good with a 5 place decimal or does it assume 2 place? how does the receiving end expect to see the number? I mean 32 bit for tempreture is a bit much I think, could be 32767.32767 to -32767.32767 degrees! or something like that. Either way I don't want to live there!!!
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  3. #3
    Join Date
    Sep 2008
    Posts
    27


    Did you find this post helpful? Yes | No

    Default

    I used this information to read floats from an AB plc and it worked fine. There is a subroutine for Int to Float.
    http://melabs.com/resources/fp.htm
    Last edited by Cobra_Phil; - 6th December 2010 at 14:23.

  4. #4
    Join Date
    Dec 2004
    Location
    nebraska
    Posts
    79


    Did you find this post helpful? Yes | No

    Default

    thanks for the replys everyone,
    Ive been gone for a while and havent had time to suddy it all yet. Ill get back to it.
    Thanks
    Nick

  5. #5
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    704


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by shawn View Post
    thanks for the replys everyone,
    Ive been gone for a while and havent had time to suddy it all yet. Ill get back to it.
    Thanks
    Nick
    Shawn,

    It looks like we were trying to reinvent the wheel. Everything that you need is provided in the melabs.com link that Cobra_Phil mentions above.

    Robert
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts