03-09-2010 06:14 AM
Hallo,
I am communicating with an instrument via VISA commands.
I am getting an output in the form of hex combination of numbers and letters.
the thing is that with all the formulas i have tried to convert it to a double i failed miserably.
From the data map i was given i figured that the following hex should have the corresponding values:
C5D1 (2 bytes) -> 26
CA EF5D CE (4 bytes) -> 957
C4E2 (2bytes) -> 14
instead i get some huge numbers.
could you please tell me how to convert those into doubles?
thank you in advance,
thodoros
Solved! Go to Solution.
03-09-2010 06:35 AM
03-09-2010 06:49 AM
03-09-2010 07:06 AM
Hi Sorry for the previous post. I am interested in Radon + error, Air pressure, Humidity and Temperature
Radon, Radon Error, Temperature, Humidity
The data format is 2-byte FLP (Floating Point), as normally described in statdataformat.
1 1000000 10000000
| | |
| | 8 bit mantissa
| |
| 7 bit exponent, offset=64
|
1bit algebraic sign (1= positive)
Conversion:
Change mantissa and exponent from hex to decimal
Result = mantissa/256 * 2exp (exponent-64)
Examples:
0 = C0 00
1 = C1 80
-2 = 42 80
0.25 = BF 80
Air Pressure
The data format is 4-byte FLP, as normally described in statdataformat. By this it is like 2-byte FLP, however with 3 byte mantissa.
for example: 10 = C4 A0 00 00
The output i get from the instrument is the following
0602 4353 0600 1003 0914 0339 1003 0914 0000 0000 0000 0000 0000 0A00 00C2 83C2 C001 0000 07C5 D6CA EF75 62C4 E1CC E834 23C9 A994 26CF 9F77 1900 4546 3135 3336 4531 3530 0350
hope that helps
03-09-2010 07:10 AM
Thodoros
When you say your trying to convert a hex to a double do you mean convert a hex to a Decimal? Or do you mean the VISA output is a string and your trying to convert it to a numeric? Do you have some sample code?
Regards
Dan
03-09-2010 07:16 AM - edited 03-09-2010 07:21 AM
Hi 21232,
you have to do some calculations on your own as you're talkinb about non-standard floating point formats... (This reminds me on some very old HP device which used their own FP formats too!)
Examples for 2 byte FLP:
0xC5D1
= 0b1100010111010001
= 1.1000101.11010001 (1bit sign, 7 bit exponent, 8 bit mantissa)
= + 2^5 * 209/256 = 26.125
0xC4E2
= 0b1100010011100010
= 1.1000100.11100010
= + 2^4 * 226/256 = 14.125
0xCAEF5DCE
= 0b11001010 0xEF5DCE
= 1.1001010 * EF5DCE
= + 2^10 * 15687118/16777216 = 957
Genug Beispiele?
03-09-2010 07:19 AM
Thank you but could you please explain to me how to do it because i really do not understand?!
it is new teritory for me.
thanks again
03-09-2010 07:22 AM
.. i mean how do i do this calculations in labview?
thanks!
03-09-2010 07:27 AM - edited 03-09-2010 07:29 AM
Hi 21232,
for any 2 byte FLP "x":
sign:
IF (x & 8000h) <> 0 THEN positive
exponent:
2^((x & 4F00h)/256)
mantissa:
(x & 00FFh)/256
result = sign*exponent*mantissa
for any 4 byte FLP "y":
sign:
IF (y & 80000000h) <> 0 THEN positive
exponent:
2^((y & 4F000000h)/2^24)
mantissa:
(y & 00FFFFFFh)/2^24
result = sign*exponent*mantissa
03-09-2010 07:32 AM - edited 03-09-2010 07:33 AM
last message continued:
- replace "THEN positive" with "THEN +1 ELSE -1"
Your description was not complete, but the part with 2^24 was rather easy to guess...
You can also make just one conversion function for both FLP type, when you multiply all 2 byte FLPs (raw value) with 2^16=65536!