Shop OBEX P1 Docs P2 Docs Learn Events
IEEE Std 754 for Float32 — Parallax Forums

IEEE Std 754 for Float32

Earl FosterEarl Foster Posts: 185
edited 2009-04-02 16:53 in Propeller 1
I have a 2 part question:
·
I have a device that will be sending data that includes Float32 information, such as heading, and I am trying to figure out how I would go about parsing that information into it component parts.· I know where in the data stream the information will start and stop but I am not sure I have the correct understanding of parsing it properly.
·
Part 1: Understanding the IEEE Std 754 format for single precision
·
Let’s say the decimal number -10.6 is coming in and is in big endian format.· The binary/hex equivalent in IEEE Std 754 for the float32 would look like this (broken down into octets for readability)
·
Binary: 11000000 00000000 00000000 01101010··· Hex: C0 00 00 6A
·
Where:
Bit 31: sign (1 = negative)
Bits 30-23: Exponent (0 < Exponent < 255)
Bits 22 – 0: Number without decimal point, ex 106
·
Part 2:
·
I am assuming I can assign C000006A to a variable then use the Float32 object to perform calculations, however, the Prop uses LITTLE ENDIAN so will I need to reverse my information and then assign to the variable?·
·
Change C000006A to 6A0000C0
·
Would appreciate someone setting me straight if I am on the wrong path.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
WWW.HAPB.NET

"Don't ask yourself what the world needs - ask yourself what makes you come alive, and then go do it." - H.T.Whitman

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-02 16:39
    It all depends on how the data is actually sent. Assuming that the data is being sent 8 bits at a time with the most significant byte sent first, then you will have to assemble it into a 32 bit long word in the proper order. The most significant byte will be stored in the highest address byte of a long and the least significant byte will be stored in the lowest address byte of the long. If the bytes are stored in a buffer, then you will have to reverse their order to make a single 32 bit long word out of them.

    In your example, the 32 bit value is written $C000006A. It's stored in memory as the following bytes: $6A, $00, $00, $C0 from lowest to highest address. If you're receiving them a byte at a time, you'll have to store them in reverse order.
  • Earl FosterEarl Foster Posts: 185
    edited 2009-04-02 16:53
    Then Big Endian and Little Endian does not make any difference in this senerio as long as I know the correct incoming format. However, if the data stream was transmitted little endian (6A0000C0) then I would NOT need to reverse the bytes (C000006A) before performing any calculations. The device I am using allows me to change from big endian to little endian, thats why I am asking.

    Thanks Mike

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    WWW.HAPB.NET

    "Don't ask yourself what the world needs - ask yourself what makes you come alive, and then go do it." - H.T.Whitman

    Post Edited (Earl Foster) : 4/2/2009 6:00:53 PM GMT
Sign In or Register to comment.