LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

To 4 bits hex?

Solved!
Go to solution

Hi all,

 

Supose that I am doing a VISA read, and the result that I expect to get is A602000000A8 in hex.  However, since I am doing a VISA read, I am going to get the Ascii equivalent of that hex.  I know how to convert the Ascii into hex, so that's not the problem.  Let me give you an example (see attachment).

 

If I expect to get A9 in hex back from the read, I should be reading \n\t from VISA read.  When I do the conversion, instead of getting A9, I get 0A09.  This is due to the fact that ASCII is 8 bits.  However, since I am expecting a Hex number, all I care about is 0-F in hex.  In another word, I only need 4 bits. 

 

In summary, how do you convert \n\t in string to A9 in hex (not 0A09).

 

Yik

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 1 of 5
(3,131 Views)

NO,NO,NO. You are not getting the 'ASCII' equivalent of hex. You are getting bytes that you choose to display as ASCII or Hex. VISA does not convert anything to anything. It just reads whatever is sent. Each

 

Hex A9 is not \r\t. Hex A9 is a single byte (8 bits!). A \n\t is two bytes (16 bits). Just right click on your string indicator and select 'Hex Display'.

Message 2 of 5
(3,120 Views)

Hi Dennis,

 

If I am supposed to read A602000000A8 in hex from VISA read, which is "displayed" as a string, and I want to process it so that at the end, I only get the first two hex number (number format), which is A6.  What is the best way of doing this?  Thanks!

 

Yik

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 3 of 5
(3,094 Views)
Solution
Accepted by topic author jyang72211
Wire the string to the String to Byte Array function. The first byte in the U8 array will be 0xA6. Make the display format hex if you don't want to convert decimal 166 in your head.
Message 4 of 5
(3,087 Views)

You are right.  I got confused for no reason.  Thank you!

 

Yik

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 5 of 5
(3,080 Views)