06-28-2013 12:48 PM
I have a vi reading in from a VISA Read a string of the format;
AAAA,BBB,CC,DDD,EEE,FF,GGGGG CRLF
The 'FF' should be a hexadecimal value, but when read in it is in string format. A simple string conversion to hex (using 'hex_bin_oct_string_conversions_LV85.vi', for example) does not work, as that results in an incorrect hex value. For example, 'FF' might equal 00. When 00 is converted with the string conversion to hex, the result is 3030. I need to convert the string '00' to a hex value of 00.
Any thoughts would be greatly appreciated.
06-28-2013 01:10 PM
Go to the String->String/Number Conversion palette. In there you will find the Hexidecimal String to Number function.
06-28-2013 01:18 PM
Thanks for the feedback, however, using that function 00 is then represented as 0. I suppose the solution is to convert the characters individually?
06-28-2013 01:33 PM - edited 06-28-2013 01:34 PM
You need to be more specific!
Are the commas and spaces you are showing real delimiters? is "CRLF" four characters or two characters?
Are the fields hexadecimally formatted strings or binary strings?
What is the desired datatype after conversion?
It would be best of you could attach a small VI containing a typical string as diagram constant. Easiest would to to run your VI with a string indicator for the received string. After that, stop the VI, right-click the terminal and "create constant". Place the constant into a new VI and attach it here.
06-28-2013 02:42 PM
@jdeters79 wrote:
Thanks for the feedback, however, using that function 00 is then represented as 0. I suppose the solution is to convert the characters individually?
Yes, the numeric value of a "00" string is 0. If you want to show it as hex, check the properties of the numeric indicator.
/Y
06-28-2013 02:42 PM
Okay, so using the Hexadecimal string to number function, I was able to convert to binary. See attached vi. Had to separate into individual characters, process, then concatenate strings.
Thanks for your feedback.
06-28-2013 03:09 PM - edited 06-28-2013 03:10 PM
@jdeters79 wrote:
Okay, so using the Hexadecimal string to number function, I was able to convert to binary. See attached vi. Had to separate into individual characters, process, then concatenate strings.
Thanks for your feedback.
You know you can use the Scan From String just as easily. And if you make the output a U64, you can handle 16 hex digits at a time.
06-28-2013 03:18 PM
Unless I'm missing something, which I probably am, that version of code results in 00 = 0000, not 00000000. It's dropping zeros.
06-28-2013 03:41 PM
try a format of "%04b". (I would probably use a lookup table instead)
06-28-2013 04:40 PM - edited 06-28-2013 04:44 PM
The main problem is that you code is not scaleable, and actually returns a truncated string for your default input of "ABC" (same as for "AB"!)
As I said, a lookup table is more reasonable, and it can scale to input strings of any length. There is even a safeguard to substitute "xxxx" for any illegal input characters.