LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert hex (or byte??) to double

Solved!
Go to solution

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

0 Kudos
Message 1 of 22
(4,705 Views)
Please provide a link to the datasheet of the instrument.
0 Kudos
Message 2 of 22
(4,695 Views)
Description of data:
Record# : 1 byte Int, number of present measuring series
NN : 1 byte, not used
Genitron Instruments GmbH 7/97 9
AlphaGUARD Data Transmission Technical description
Date/time : 6 byte BCD, present date (YYMMDDHHMMSS)
Lastsave : 6 byte BCD, time of present measuring value
NN : 8 byte, not used
Cycle time : 1 byte, measuring cycle (10 or 60 min)
NN : 2 byte, not used
Radon : 2 byte FLP
Radon error : 2 byte FLP
DATA_QA : 1 byte Int
SYS_QA : 1 byte Int
RELOC : 1 byte Int, relocation sensor
EXT_IN : 1 byte Int, external input
Temperature : 2 byte FLP
Air pressure : 4 byte FLP
Air humidity : 2 byte FLP
Akkustd : 4 byte FLP, operation hours of akku
KBeqstd : 4 byte FLP, total radon integral
Totalstd : 4 byte FLP, total operating hours
NN : 1 byte, not used
Serial# : 6 byte ASCII, serial number
Version : 4 byte ASCII, version number of firmware
0 Kudos
Message 3 of 22
(4,688 Views)

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

 

0 Kudos
Message 4 of 22
(4,677 Views)

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

Herrlin

Just trying to spread the LabVIEW love.
0 Kudos
Message 5 of 22
(4,675 Views)

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?

 

Message Edited by GerdW on 03-09-2010 02:21 PM
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 22
(4,665 Views)

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

0 Kudos
Message 7 of 22
(4,661 Views)

.. i mean how do i do this calculations in labview?

thanks!

0 Kudos
Message 8 of 22
(4,655 Views)

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

Message Edited by GerdW on 03-09-2010 02:29 PM
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 22
(4,648 Views)

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!

Message Edited by GerdW on 03-09-2010 02:33 PM
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 22
(4,638 Views)