LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Converting a string representing hex into a string of the corresponding ascii characters

Hi,

 

I would like to be able to convert a string of hex values into a string of the ascii characters that those hex values represent.

 

For example:

 

4B233F357A

 

would become:

 

K#?5z

Any suggestions most welcome.

 

Cheers,

Dan

0 Kudos
Message 1 of 13
(4,955 Views)

Hi Dan,

you can use the "type cast" function.

 

Mike

Message 2 of 13
(4,952 Views)

Hi Dan,

 

when having a "string of hex values" instead of a "hex string" the example shows a straight-forward, simple solution...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 13
(4,940 Views)

Hi Dan,

sorry, it was the wrong picture. I'm not sure what happend there. 🙂

 

Mike

0 Kudos
Message 4 of 13
(4,937 Views)

Hi Dan,

 

I've attached a piece of code that I wrote for a customer a while back. It takes in a Hex String Array and converts it into ASCII. I have attached a picture below but there is a more complete explanation on the community pages linked here

 

 untitled.JPG

 

 Many thanks,

Andrew McLennan
Applications Engineer
National Instruments
0 Kudos
Message 5 of 13
(4,895 Views)

Hi Andrew,

 

as Application engineer you should provide code for others to learn from! Smiley Wink

 

- Use boolean operations directly on integer numbers

- Q&R avoids type coercions

- ArrayInterleave avoids a FOR loop

- simplify case structures

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 13
(4,871 Views)

I'd like to nominate Andrew's code for Rube Goldberg status.

 

As I can't post files/images from here. I present a text description of my equivalent code.

 

The HEX and NORMAL format arrays are respectively, the auto-index input and output of a FOR loop.

 

Within the for loop, the string input feeds to string to byte array, the byte array to number to hexadecimal string (length=constant 2), the hex string is the single input of concatenate strings, the concatenated string goes to the auto-index string output.

 

One for loop, no cases, no boolean algebra, no red dots.

 

Rod.

 

Message 7 of 13
(4,862 Views)

Hi Rod,

 

I have tried to recreate your code below and I concede that my code wasn't perhaps the simplest piece of coding in the world. Although as we say on the training courses "These are not the only solutions, you may in fact find better, more efficient ways of doing things". This would definitely be one of these cases.

 

I can't work out how you got rid of the coercion dots so if you want to post, I shall try and update. I think what I've attached describes what you have done.

 

 StringConverter.JPG

 

Many thanks,

Andrew McLennan
Applications Engineer
National Instruments
0 Kudos
Message 8 of 13
(4,848 Views)

Hi Andrew,

 

Just get rid of the "To I32" and you've got it, ie wire the U8 array directly to the [polymorphic] number to hex string. I'm using rev 8.2

 

BTW: This is a diversion as Gerd's posted VI answered the original query.

 

Rod.

 

Message 9 of 13
(4,839 Views)

Gerd,

 

Nice answer.

 


 

Andrew,

 

Your code scares me.  Please consider modifying your post in the communities.  Here is a much easier way to do this.

 

SerialConverter Redo_BD.png

Message 10 of 13
(4,822 Views)