08-14-2010 10:41 AM
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
Solved! Go to Solution.
08-14-2010 11:18 AM
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!
08-14-2010 11:56 AM
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"
08-15-2010 02:49 AM
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.
08-15-2010 07:55 AM
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...
08-15-2010 09:19 AM
And why are you using Hyperterminal? Use LabVIEW with a VISA Read and do the conversion.
08-15-2010 10:25 PM - edited 08-15-2010 10:26 PM
sorry with the typo hyperterminal.im using visa read only.
most of new users will not be knowing VISA read so i wrote hyperterminal
08-15-2010 10:38 PM
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 |
08-15-2010 10:40 PM - edited 08-15-2010 10:45 PM
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.
08-15-2010 10:45 PM
ok i understood and thanks for opening a gateway for me.. ill check how it works