LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert "hex string" to hex

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.

 

 

0 Kudos
Message 1 of 12
(3,822 Views)

Go to the String->String/Number Conversion palette.  In there you will find the Hexidecimal String to Number function.


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
(3,804 Views)

Thanks for the feedback, however, using that function 00 is then represented as 0.  I suppose the solution is to convert the characters individually?  

0 Kudos
Message 3 of 12
(3,800 Views)

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.

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

@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

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 5 of 12
(3,779 Views)

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.

0 Kudos
Message 6 of 12
(3,778 Views)

@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.


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 7 of 12
(3,773 Views)

Unless I'm missing something, which I probably am, that version of code results in 00 = 0000, not 00000000.  It's dropping zeros.

0 Kudos
Message 8 of 12
(3,766 Views)

try a format of "%04b". (I would probably use a lookup table instead)

0 Kudos
Message 9 of 12
(3,760 Views)

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.

 

Download All
0 Kudos
Message 10 of 12
(3,745 Views)