grmc Posted January 13, 2005 Report Share Posted January 13, 2005 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 Quote Link to comment
jpdrolet Posted January 13, 2005 Report Share Posted January 13, 2005 That should do what you want: Quote Link to comment
RandyR Posted January 13, 2005 Report Share Posted January 13, 2005 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 Quote Link to comment
grmc Posted January 18, 2005 Author Report Share Posted January 18, 2005 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 Quote Link to comment
RandyR Posted January 18, 2005 Report Share Posted January 18, 2005 When I open it in notepad, it reads 8DI 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 Quote Link to comment
grmc Posted January 18, 2005 Author Report Share Posted January 18, 2005 You were basically on the right track, although I think this is a bit more straight-forward.Randy 3560[/snapback] Excellent! I was sure there would be a better way! Thanks a lot Randy Quote Link to comment
RandyR Posted January 19, 2005 Report Share Posted January 19, 2005 Excellent! I was sure there would be a better way! Thanks a lot Randy 3575[/snapback] You're welcome... Glad I could help. Randy Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.