LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

converting ascii string to a hex string

hi all

 

having a bit of data manipulation trouble here.

 

i am receiving an ascii string over ethernet. when i displayy it as HEX code on my front panel i get the following:

 

1025 2C68 00AD 7640 0004 0004 1100 0077 1111 11FA

 

this is fine and correct. however i need to write this to a text file as well. all i get doing this is ascii "garbage"

 

i have tried to convert it to hex string using cast to decimal the decimal number to hex string but all i get is this (or variations depending on the representation i use for the cast):

 

00000000000000000000000010252C6700AD7258

 

im not sure what representation to use etc.

 

help would be appreciated

 

regards

0 Kudos
Message 1 of 12
(4,454 Views)

Use String To Byte Array followed by Number To Hex String.  Throw in a Concatinate String to change the array of strings into a single string.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 12
(4,439 Views)

the string in is ascii. will that code still work as is?

0 Kudos
Message 3 of 12
(4,434 Views)

You said you displayed what you got in a string that is set to hexidecimal display.  That is what I gave you as the input.  And that is just the display.  The data doesn't matter.  That code will give you a string that shows the hexidecimal representation of the data in and ASCII text format.

 

Have to be really careful in how we state what is hex vs ASCII.  It gets confusion way too easily.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 12
(4,419 Views)

yes.

 

thats on my front panel. however it doesnt appear in the text file i write to like that. its ascii with all the missing chars etc.

 

i need to change the received string from the ethernet to a readable format in the text file (just like the front panel hex code thing does).

 

i did manage this a couple of weeks ago but have forgotten how i did it.

 

note that i nearly get what i want from the casting, but there are loads of leading zeros.

0 Kudos
Message 5 of 12
(4,404 Views)

What you see in the String Out (normal) is what it iwll look like in a text file editor.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 12
(4,388 Views)
The solution that you've been given does not use any type cast so you are obviously not using that. Why not? Why ask a question and ignore the answer?
0 Kudos
Message 7 of 12
(4,385 Views)

i am using type cast.

 

to decimal then using number to hex string.

 

i have just noted that my string is larger than 16 characters. but when i try and make the width bigger than16 on the number to hex string all it does is add leading zeros.

 

im obviously being stupid........

0 Kudos
Message 8 of 12
(4,376 Views)

tried what you posted and that worked fine

 

apologoes and many thanks

0 Kudos
Message 9 of 12
(4,365 Views)

actually spoke too soon

 

yes it does work, but if you get a byte of 00 it appears to strip that out and it not a part of the resultant string

 

 

ho hum

0 Kudos
Message 10 of 12
(4,348 Views)