Discussion:
Hexadecimal to "readable" string
(too old to reply)
shivels
2008-08-06 22:10:06 UTC
Permalink
Hi,
I have written a program which opens a file, converts the contents of the file to hexadecimal and outputs the decimal values.  The program works great for giving me the decimal values, but the file also contains readable works like xsize, ysize.  All of the readable word lines begin with a comment character, #.  I have used the string-to-byte-array to generate the ASCII, but how do I take these values and translate them into works like # xisze, # ysize, ect?  The byte array gives me values like 38, 57, 58, 34, but looking at the ASCII table, these values are numebrs like 7,8,0.  Is there another conversion I have to do before I can get the corrsponding readable letter?
 
Adam
smercurio_fc
2008-08-06 22:40:05 UTC
Permalink
My guess is that you're displaying the byte value as a decimal, and assuming it's displayed in hex. Unless you change the format, a numeric indicator displays in decimal. For instance, an ASCII decimal value of 35 corresponds to "#". The hex value is 23.
shivels
2008-08-06 23:40:05 UTC
Permalink
Right now i have all the converted values displayed as both numeric array indicators and string indicators.  I am displaying the value as normal, when I display it as hex, I get values like 3030 3032 etc.  When I display it normal, I get values like 02000000.  How can I use the byte array values to convert them back into readable numbers?  I think I'm missing a really simple step, but I just can seem to figure it out.
 
Adam
JoeLabView
2008-08-07 01:10:07 UTC
Permalink
I'm not sure I completely follow what you are looking for..
Are you trying to have a string that contains the HEX equivalent of the original string?
Let's see if I understood:  Say you have the word "Hello", it's ASCII equivalent in Hexadecimal is:  0x48 0x65 0x6C 0x6C 0x6F
And you would want a string that contains:  48 65 6C 6C 6F
If that is what you are looking for, please see attached VI.
Otherwise, please try again to explain what you need.
R
<img src="Loading Image..."> Message Edited by JoeLabView on 08-06-2008 08:43 PM


HexedString.vi:
http://forums.ni.com/attachments/ni/170/347325/1/HexedString.vi


HexedString_FP.png:
http://forums.ni.com/attachments/ni/170/347325/2/HexedString_FP.png
shivels
2008-08-07 01:40:05 UTC
Permalink
Yes thats a great of example of what I was looking for.&nbsp; I understand everything except how to take the values 48 65 6C 6C 6F and convert them back into "Hello", so I can write it to a file.&nbsp; I feel like its something little I can't seem to understand.
&nbsp;
Adam
ian fung
2008-08-07 02:10:05 UTC
Permalink
This VI function does it... with/without space between bytes


LVVILIB_STR_Norm Str to ASCII (npw).vi:
http://forums.ni.com/attachments/ni/170/347333/1/LVVILIB_STR_Norm Str to ASCII (npw).vi
shivels
2008-08-07 03:10:04 UTC
Permalink
Thank you so much, this is exactly what I was looking for.
Adam
JoeLabView
2008-08-07 12:40:12 UTC
Permalink
Now please explain if I took the time to prepare an example for you that you gave me a 3 star rating?&nbsp;
smercurio_fc
2008-08-07 14:10:07 UTC
Permalink
I still don't understand what was being asked here, and I'm thinking that Ian's solution is more complicated than it needs to be if all you're dealing with is ASCII values to letter conversion. Ian: You while loop can be replaced by a simple SpreadSheet String to Array function. Also, you should not lock VIs that you post to this forum. Any VIs that you post are public, and while a user can unlock it, it's considered bad form to post it that way. If you don't want somebody modifying your code, then you shouldn't post it. Message Edited by smercurio_fc on 08-07-2008 08:59 AM
JoeLabView
2008-08-07 16:10:05 UTC
Permalink
Thanks for posting Saverio,
I thought it was just me who didn't understand what the person was asking...&nbsp; Had he/she been MORE clear, my example would have been more appropriate.&nbsp; Heck, a simple change was all that was needed to achive the end solution.&nbsp; As you said no loops involved...
Also, my belief is to provide a generic solution so that the person asking the question can have a clue how to solve the problem..&nbsp;&nbsp;That way, they can learn instead of always relying on others..&nbsp;
shivels, to learn more about LabVIEW, I suggest you try looking at some of <a href="http://wiki.lavag.org/LabVIEW_tutorial#External_Links" target="_blank"> these tutorials</a>.
R
ian fung
2008-08-07 16:40:05 UTC
Permalink
Dear smercurio_fc
Thanks for the advice...
I just wish to point out that the VI was not lock by any password... all that you need to do is CTRL+M
So, it's for public ;)
shivels
2008-08-08 15:10:11 UTC
Permalink
Hi,
I have a file which contains alphabet words and decimal values.&nbsp;&nbsp;After the file is processed, it comes out looking like the attachment.&nbsp;&nbsp;I convert the file to hexadecimal.&nbsp; I then convert the hexadecimal values to decimal values.&nbsp; I am able to&nbsp;find the original decimal values in&nbsp;my converted array.&nbsp; I&nbsp;am now trying to locate the alphabet words in the file.&nbsp; I have converted the hex string into a byte array and get ASCII values, but when I convert those&nbsp;using an ASCII table, I get non-sense words.&nbsp; I think there is a simple conversion step I am missing.
Adam&nbsp;


_1.osc:
http://forums.ni.com/attachments/ni/170/347893/1/_1.osc
smercurio_fc
2008-08-08 15:10:12 UTC
Permalink
I do not understand these statements: I convert the file to hexadecimal.&nbsp; I then convert the hexadecimal values to decimal values.&nbsp; If you're looking for the text information simply read the file as a text file directly, and then search the string using, for example, Match Pattern:<img src="Loading Image..."> Message Edited by smercurio_fc on 08-08-2008 10:07 AM


Example_VI.png:
http://forums.ni.com/attachments/ni/170/347897/1/Example_VI.png

smercurio_fc
2008-08-07 16:40:06 UTC
Permalink
Yes, I'm well aware of that. But there's a lot of new people using LabVIEW that don't yet know that and would get quite annoyed at that. Just saying. :smileywink:
ian fung
2008-08-07 16:40:06 UTC
Permalink
I am sorry if that does not make anyone new to labview learn about using CTRL+M as well...
&nbsp;
All I was doing to trying to help. Let's put a full stop here. Thanks for your advice.
Loading...