LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert hex string to ascii

Ok I have a hex string

09124E4F21CD0024FFFFFFFFFFFFFFFF

which is really 16 ascii characters.


Could someone point me in the right direction to convert strings like this to the ascii characters

thanks
0 Kudos
Message 1 of 9
(21,599 Views)
You just have to set the string display from Normal to Hex by right clicking on the string control/indicator. The Hex display shows the ASCII code of the characters. See attached vi. When sending strings to something like a serial port, there is no need to convert to ASCII code. Just send the character string. If receiving a character string and you want to see the ASCII code, just set the indicator for Hex display. I have no idea why NI calls this Hex display when it is really ASCII code display. It is very misleading. People tend to think that the Hex display shows hex values, like a string containing "255" will show up as "FF". Not true. In Hex display, the "255" string will look like "323535" since the character "2" has an ASCII code of 32 and a "5" is 35. It has nothing to do with Hex at all! Can someone explain why it is called Hex display?
- tbob

Inventor of the WORM Global
0 Kudos
Message 2 of 9
(21,601 Views)
in my case simply changing how its displayed will not work

09h = a tab character in ascii not 30 39
0 Kudos
Message 3 of 9
(21,598 Views)
If your string is 32 characters of HEX formatted text and you want to convert it to the underlying ASCII string, you can for example use "Hexadecimal string to number" for each octet in a loop creating an U8 array to be converted to string. See attached example.

If this is not what you need, please explain exactly the representation of your original string.
Message 4 of 9
(21,590 Views)
thats what i needed thanks much
Message 5 of 9
(21,586 Views)

@tbob wrote:
...I have no idea why NI calls this Hex display when it is really ASCII code display. It is very misleading ... It has nothing to do with Hex at all! Can someone explain why it is called Hex display?


The ASCII code of the letter A is forty one.

- Could you write down this ASCII code for me please ?
- No problem ! here it is : FORTY ONE...
- Euh ?! I mean as a number!..
- Sorry ! here we are : 101001.
- Thanks. So the ASCII code of A is one zero one zero zero one...

Sure, if you don't state the base into which you want the code to be expressed, some discussions could last for ever...
Of course, this is what "HEX display" mean : ASCII code as hex values by opposition with "\" display (ASCII code in base10).
Is it really necessary to increase the menu lenght ?

CC
Chilly Charly    (aka CC)
Message 6 of 9
(21,580 Views)
Just to clear up what CC said (I had to think about it for a couple of seconds myself) - A is ascii 65, which in hex is 41. 2 is ascii 50, which in hex is 32. This can be confusing if you don't have numbers with A-F and don't know the setup of the ascii table.

___________________
Try to take over the world!
0 Kudos
Message 7 of 9
(21,575 Views)
I am used to seeing ASCII code as a decimal number. I had no idea that Hex display meant the ASCII code in Hex format, seems pretty obvious now. Thanks for clearing it up.
More confusion can come in regarding whether the string indicator is a string of characters or a string converted from a byte array. The attached vi shows that normal display and hex display can be different things depending on whether the string is a string of characters (similar to a character array in C), or a string display of numbers (similar to a byte array). In one case the string "123" is made up of the characters "1", "2", and "3". In the other case, the string is an actual number one hundred twenty three. In the character case, the normal display shows "123", while the hex display shows ASCII code for "1", "2", and "3" in hex. In the number case, the normal display shows the character representation of the ASCII code given by the number, while the hex display shows the hex value of the number.
To make it less confusing, the normal display is always ASCII characters, and the hex display is always ASCII code in hex. My head is spinning so I won't even attempt to tackle '\'codes display.
- tbob

Inventor of the WORM Global
0 Kudos
Message 8 of 9
(21,550 Views)
tbob,

You wrote:
"To make it less confusing, ... the hex display is always ASCII code in hex"

On another hand, it may make it less confusing if you think of a "string" as just a series of bits in bytes, and Hex display as a way of showing the bit pattern that's more compact than writing a lot of 0's and 1's. Sometimes the bytes happen to be ASCII code, sometimes not. For example, the 32 bits

0111 0100 0110 0010 0110 1001 0110 0010 is 0x 74626962

Depending on what is being done, they could represent:
- a misspelling of your user name;
- a SGL or a U32;
- 32 digital outputs on some device with 14 of them on;
- a couple of 4 digit binary coded decimal numbers;
- and a lot of other things.

All but the first have appeared in this forum at some time (and maybe I just missed the misspelling thread).

As far as "\" codes go:
Back before grunge came out of Seattle, there was no Hex display for strings in LabVIEW ... just Normal and "\" code, so it was a bit harder to decipher bytes coming in a serial port. Still is useful though for finding extra spaces etc. in text.

Apologies again if this contributes to more head spinning.
=====================================================
Fading out. " ... J. Arthur Rank on gong."
Message 9 of 9
(21,522 Views)