Jump to content

String to Hex conversion?


Recommended Posts

Hi all,

I'm having a bit of trouble converting from a String to the same value in Hex.

E.g. -

I have a text file, with which I store HEX values in a String format.

I read these values into my app in String format, but I need to convert these back into Hex format for my app to work properly.

So basically, if I read in 8D from a text file, I need to be able to write 8D (in hex) through the serial port.

The generic String to Hex conversions do not seem to do what I need them to do.

If anyone has any ideas, that would be greatly appreciated.

Cheers,

grmc

Link to comment

Well, it's not clear to me what you mean when you say "HEX values in String format".

Does this mean your 8D from file is 8D ASCII or Binary? In other words, if you open the file in notepad, does it show an 8D or a non-printable character?

If the 8D is stored binary, then you don't have to do anything to it to prep it for the serial port.

If you haven't noticed the option, the hex and normal display mode options in the string indicator pop-up menu will help you out.

If it's stored as an ASCII 8D, then you need to use scan from string to convert to an int and then type cast it back to a string. Optionally there are the byte array to string and string to byte array primitives that may be of some help.

Randy

post-767-1105583260.jpg?width=400

Link to comment
Well, it's not clear to me what you mean when you say "HEX values in String format".

Does this mean your 8D from file is 8D ASCII or Binary? In other words, if you open the file in notepad, does it show an 8D or a non-printable character?

If the 8D is stored binary, then you don't have to do anything to it to prep it for the serial port.

If you haven't noticed the option, the hex and normal display mode options in the string indicator pop-up menu will help you out.

If it's stored as an ASCII 8D, then you need to use scan from string to convert to an int and then type cast it back to a string. Optionally there are the byte array to string and string to byte array primitives that may be of some help.

Randy

3488[/snapback]

When I open it in notepad, it reads 8D

I had a lot of trouble attempting to convert it and typecast it to the value I wanted, so I created this vi which does the trick, albeit in a very backwards fashion!

Surely there has to be a faster / simpler way than this!

Download File:post-854-1106017813.vi

Link to comment
When I open it in notepad, it reads 8D

I had a lot of trouble attempting to convert it and typecast it to the value I wanted, so I created this vi which does the trick, albeit in a very backwards fashion!

Surely there has to be a faster / simpler way than this!

3559[/snapback]

You were basically on the right track, although I think this is a bit more straight-forward.

Randy

Download File:post-767-1106019390.vi

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.