Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Converting Hex string to ASCII numeric

I have a device that only uses hexadecimal data for it's communication. Therefore, the data I get back from it is in hexadecimal, rather than an ASCII numeric as I would like. How is it that I can convert a string of Hexadecimal to a numeric value? I know I can use the type cast function to convert the data into a hexadecimal ASCII string, but I don't know what to do from there. Please help.

JohnGalt
----------------------------------------------------------------------------------------------------------------------------------------------------
I've got a sneaking suspicion that Jesus might have been made of bread. Why else did they have to put him in a warm cave and wait three days for him to rise?

Damnant quadnon intelligunt - They condemn what they do not understand.
0 Kudos
Message 1 of 16
(5,722 Views)
Hi
 
first make really sure that the string indeed is a hexadecimal representation.
(in that case you always see an even number of characters and all in the range 0..9 and A..F (looking at the pure string.)
if you see any other value it is not hex but binary !
 
this hex string should be broken up into pieces of two characters and fed to the hexstring to number (see vi)
 
greetings from the Netherlands
Message 2 of 16
(5,720 Views)
Well, it actually is a normal string, so the hex comes out as a really weird bunch of ASCII symbols, but when you change the string indicator to hex view, it is correct. What I want to do is to take that and convert it into an ASCII string (or a numeric value would work too) that represents the decimal value of the hexadecimal data sent by the RF generator. I hope that made sense.

PS. The program you attached is in Labview 8.0. I only have 7.0. Can you convert that so that I can use it, please?

Thank you,
JohnGalt
----------------------------------------------------------------------------------------------------------------------------------------------------
I've got a sneaking suspicion that Jesus might have been made of bread. Why else did they have to put him in a warm cave and wait three days for him to rise?

Damnant quadnon intelligunt - They condemn what they do not understand.
0 Kudos
Message 3 of 16
(5,717 Views)

Actually it was 7.0 so here is a version now.

But as I said if it does not look like hex in the raw string it is not hex but bytes.

so simply use the string to byte array and you are ready, I use the inverse in my program to get from bytes to a string.

A lot of people don't get the meaning of hex or binary or decimal. But think of it as the way you look at the contents, te values don't change

only the way we display them.

A lot of manufacturers are mixing up hex in the manual with bytes to the machine. I guess you don't have to do anything else than

convert the string to a byte array and in that byte array let the numbers display the radix and set that to hex.

succes

 

greetings from the Netherlands
0 Kudos
Message 4 of 16
(5,712 Views)
That program didn't seem to help. It just reduced the data bytes I get by one. I will try to be more specific, since after reading over my earlier posts, it is a bit unclear. The data I have is decimal, displayed as ASCII characters. In other words, a normal string that you get from a VISA device. What I want to do is take that string, and convert it so that the data of the hexadecimal values of the ASCII characters become the ASCII characters of the final string. Does that make sense?

JohnGalt
----------------------------------------------------------------------------------------------------------------------------------------------------
I've got a sneaking suspicion that Jesus might have been made of bread. Why else did they have to put him in a warm cave and wait three days for him to rise?

Damnant quadnon intelligunt - They condemn what they do not understand.
0 Kudos
Message 5 of 16
(5,708 Views)

What is so nice about the ascii values in a string

If you have the bytes in an array you can look at them in hexadecimal.representation by rightcliking in one of the bytes of the array
select display radix and in the radix select hexadecimal

 

see a very compact program attached

greetings from the Netherlands
0 Kudos
Message 6 of 16
(5,702 Views)
Sorry, that does indeed give me the numerical value of the bytes, but is there a way those bytes can be combined into one number? The manual says that the two bytes represent the value of the forward power, but I don't know how to combine them to get one value out of the two.
----------------------------------------------------------------------------------------------------------------------------------------------------
I've got a sneaking suspicion that Jesus might have been made of bread. Why else did they have to put him in a warm cave and wait three days for him to rise?

Damnant quadnon intelligunt - They condemn what they do not understand.
0 Kudos
Message 7 of 16
(5,691 Views)

Perhaps this is what are you looking for .

Regards

PS: I just verified that Albert and I gave you the same answer...sorry...why don't you send us an example?

I understood that you want to convert "3456" string to 34hex and 56hex relative ascii char obtaining "4V".

Message Edited by antea06 on 05-12-2006 09:50 AM

CLD - Labview Certified Developer
0 Kudos
Message 8 of 16
(5,687 Views)
Ok. I will attach an example to this which has a little more detail about what I want. BTW, the program you posted is too recent for my poor outdated computerSmiley Sad. I only have 7.0.

Thanks for the help
JohnGalt

Message Edited by JohnGalt on 05-12-2006 11:22 AM

----------------------------------------------------------------------------------------------------------------------------------------------------
I've got a sneaking suspicion that Jesus might have been made of bread. Why else did they have to put him in a warm cave and wait three days for him to rise?

Damnant quadnon intelligunt - They condemn what they do not understand.
0 Kudos
Message 9 of 16
(5,679 Views)
Does it work as you want?
 
CLD - Labview Certified Developer
Message 10 of 16
(5,646 Views)