LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

hex to ascii

Solved!
Go to solution

Now if i convert hex to ASCII and then back to HEX will the data be same.

youll say yes.I know.this holds good if the data is char or string

my question is what if double,int,float are converted to hex format and then converted to ASCII format and then back to hex format.

will the data be same.HELP

 

 

-------------------------------------------------------------
kudos welcome
0 Kudos
Message 1 of 11
(5,888 Views)

Please explain what you mean, because there are many ways to go from numeric to string.

 

The terms HEX and ASCII have no meaning unless you explain exactly what you are trying to do.

 

If you take a numeric (DBL, I32, U8, CXT, etc), you can represent it as a string using typecast or flatten to string, and the information will be retained bit by bit. If you later unflatten or typecast it back, nothing is lost.

Here, the resulting string is typically to readable, unless the string is displayed in hex format.

 

If you talk about formatting, you might lose a lot of information irreversibly. You can only format integers to hex format. If you format a DBL to a decimal string representation, you need to ensure that you show enough decimal digits. Even if you do, there will be small differences due to the inability to fully represent certain fractions in the other numeric system (binary vs. decimal). A formatted string is typically readable directly.

 

Please provide more information!

Message 2 of 11
(5,880 Views)

Sorry for the typo, the sentence above should read:

 

"Here, the resulting string is typically NOT readable, unless the string is displayed in hex format"

0 Kudos
Message 3 of 11
(5,871 Views)

hey altenbach,thanks for your response

Here im getting some data in HEX format from microcontroller to my computer using serial communication through hyperterminal.

As the Hyperterminal read data in ASCII format,i'm forced to convert it back to HEX format.

So my question was like is it possible to retain data(in HEX format)with out loss.

Im getting string corretly as string is of 1byte,but int, float,double these are the problem.Can i retain there values with out any loss.

-------------------------------------------------------------
kudos welcome
0 Kudos
Message 4 of 11
(5,851 Views)

Hi omprakash,

 

yes, you can - using typecast, unflatten, or simple math...

 

Give examples, of what you receive and what you expect - then you will get LV example code back!

As Altenbach said: "HEX" is meaningless unless you provide exact examples...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 5 of 11
(5,843 Views)

And why are you using Hyperterminal? Use LabVIEW with a VISA Read and do the conversion.

0 Kudos
Message 6 of 11
(5,836 Views)

 

-------------------------------------------------------------
kudos welcome
0 Kudos
Message 7 of 11
(5,807 Views)

Hi GredW,

 

1st 16byte char then sent 8byte long then unsignedint 4byte

 

This is the order in which data is dumped in to serial read continuosly...

 

 

char

Long

Unsigned int

16byte

8byte

4byte

-------------------------------------------------------------
kudos welcome
0 Kudos
Message 8 of 11
(5,801 Views)
Solution
Accepted by topic author omprakash

Users here are more familiar with using VISA and incorrect statements are just confusing. And you are wrong about reading as ASCII. The data read is strings - a byte at a time and it is just the default front panel display that is ASCII. You can display the data in any format you want (simply right click and select hex diplay for example) and assuming you actually know what format those bytes you read are supposed to represent. Use the functions you have already been given (i.e. unflatten from string) to do the conversion. You can read x number of bytes, use the String to byte array, and use Array Subset to get segments you want for different conversions.

Message 9 of 11
(5,797 Views)

ok i understood and thanks for opening a gateway for me.. ill check how it works

-------------------------------------------------------------
kudos welcome
0 Kudos
Message 10 of 11
(5,794 Views)