LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I convert a hex number to binary

I thought this would be relatively easy but I have not found the solution yet. I am getting a hex string from the serial port on my UUT. I want to convert that string to its numerical binary equivalent. Is there a way to do that? If I have to go from a hex string to a hex number first that is fine. But the end result is I have to take my hex string and get it down to its binary equivalent in numerical form. Any help would be appreciated.
0 Kudos
Message 1 of 3
(2,818 Views)
Hello Trosier,
You can bring your string in and convert it to hex using the string to hex vi. You need to go to the format & precission of the numeric indicator and change it from floating point to binary. This will display the binary value of the number.
Hope this helps,
Ben
0 Kudos
Message 2 of 3
(2,812 Views)
Could you clarify what you mean by "hex string"? I can think of at least two interpretations (and (1) is more likely):

(1) The string is already the binary representation of the number (meaning the string will probably look like garbage unless you select HEX display for the string indicator). In this case you need to know the data type of the number (e.g. U8, I32, etc.) and if it is more than one byte you also need to know if it is big- or little-endian.

---> Use typecast with the string as input and a constant of the desired data type as type input (assuming big-endian).
Check the documentation of your serial device for the exact specifications.

(2) The string is formatted text using the letters 0-9 and A-F to represent the hex values.
---> In this case you would use Hexadecimal string to number.

If you have problems, please attach a small VI with a string diagram constant containing some raw data as received. We should be able to figure it out.
Message 3 of 3
(2,805 Views)