IEEE 754 Converter
-
Hi, i have a problem concerning float values. I receive a 4 Byte value through the serial port in the following order: SEEEEEEE EMMMMMMM MMMMMMMM MMMMMMMM S - Sign E - Exponent M - Mantissa so, for example i have: 43h 89h 80h 00h (h...hexadecimal) which is the decimal value of: 275.0 My question is, if anybody knows a way of converting the 4 Byte value to the float value. Thanks in advance for any help you can provide
-
Hi, i have a problem concerning float values. I receive a 4 Byte value through the serial port in the following order: SEEEEEEE EMMMMMMM MMMMMMMM MMMMMMMM S - Sign E - Exponent M - Mantissa so, for example i have: 43h 89h 80h 00h (h...hexadecimal) which is the decimal value of: 275.0 My question is, if anybody knows a way of converting the 4 Byte value to the float value. Thanks in advance for any help you can provide
In C++, you would write
number = (sign ? -1:1) * 2^(exponent) * 1.(mantissa bits)
-
Hi, i have a problem concerning float values. I receive a 4 Byte value through the serial port in the following order: SEEEEEEE EMMMMMMM MMMMMMMM MMMMMMMM S - Sign E - Exponent M - Mantissa so, for example i have: 43h 89h 80h 00h (h...hexadecimal) which is the decimal value of: 275.0 My question is, if anybody knows a way of converting the 4 Byte value to the float value. Thanks in advance for any help you can provide
-
In C++, you would write
number = (sign ? -1:1) * 2^(exponent) * 1.(mantissa bits)
Actually, with C++ you can be more extreme, for instance:
unsigned char myBytes[4]={0x43, 0x89, 0x80, 0x00};
unsigned char myReversedBytes[4];myReversedBytes[0] = myBytes[3];
myReversedBytes[1] = myBytes[2];
myReversedBytes[2] = myBytes[1];
myReversedBytes[3] = myBytes[0];
float f = *(float *)myReversedBytes;Note that if you're lucky the original bytes have not to be reversed. :-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
Hi, i have a problem concerning float values. I receive a 4 Byte value through the serial port in the following order: SEEEEEEE EMMMMMMM MMMMMMMM MMMMMMMM S - Sign E - Exponent M - Mantissa so, for example i have: 43h 89h 80h 00h (h...hexadecimal) which is the decimal value of: 275.0 My question is, if anybody knows a way of converting the 4 Byte value to the float value. Thanks in advance for any help you can provide
Note that, If you intend to use the Guffa solution (that indeed is the correct one), then you have to reverse the order of the bytes to get the correct result. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
Hi, i have a problem concerning float values. I receive a 4 Byte value through the serial port in the following order: SEEEEEEE EMMMMMMM MMMMMMMM MMMMMMMM S - Sign E - Exponent M - Mantissa so, for example i have: 43h 89h 80h 00h (h...hexadecimal) which is the decimal value of: 275.0 My question is, if anybody knows a way of converting the 4 Byte value to the float value. Thanks in advance for any help you can provide
Sounds like you need a
union
. :)Cheers, Vıkram.
After all is said and done, much is said and little is done.
-
Note that, If you intend to use the Guffa solution (that indeed is the correct one), then you have to reverse the order of the bytes to get the correct result. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
Sounds like you need a
union
. :)Cheers, Vıkram.
After all is said and done, much is said and little is done.
Vikram A Punathambekar wrote:
Sounds like you need a union.
AFAIK C# doesn't provide it.:)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
Vikram A Punathambekar wrote:
Sounds like you need a union.
AFAIK C# doesn't provide it.:)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
[bangs head against wall]
Cheers, Vıkram.
After all is said and done, much is said and little is done.