IEEE Std 754 for Float32
Earl Foster
Posts: 185
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
·
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
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.
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