LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

hex string to number

I've gotten fed up with the hex string to number vi as well as the scan from string vi.  I am reading from an SR245 that is dumping data over a serial port in binary format.  The VISA read buffer is a string that looks like this when I set it to hex display:
 
13DD 13DC 13DF FF
 
The last number is junk.  I need each of the words prior to the FF (could range from 1 to 4000 words) as hex words so I can do some math.   Can someone help me out?  Thx.  Still learning.  Jonathan
Message 1 of 4
(7,541 Views)
You did not say what word size you want, but you could e.g. take the subsctring of the first 6 characters and typecast it as an aray of 3 U16 elements.
 
Simply use typecast and wire an empty array diagram constant of U16 to the type input. It is possible that your binary string is little, endian. In this case you need to reverse the byte order. On newer version of LabVIEW, you can also use unflatten from string and specify the byte order directly (LabVIEW is always big-endian.)
Message 2 of 4
(7,532 Views)
Here's a quick example assuming U16 words (since the array without the FF is even, you don't even need to trim it off):
 
You can adapt it to any other word size by changing the type (e.g U32 or U64).
 
 
 
 
 
 
 


Message Edited by altenbach on 01-22-2008 05:10 PM
Message 3 of 4
(7,529 Views)
Thanks, Alt.  So much to learn.  J
0 Kudos
Message 4 of 4
(7,492 Views)