LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I read a hex value and then convert to the binary equivalent?

I am reading hex values from a register on my unit under test. I only want to monitor certain bits in the hex value to check a status. I have everything down to run the program except how to read my hex values in binary form. Any suggestions out there?
0 Kudos
Message 1 of 7
(4,477 Views)
If this is just a matter of display, then right click and choose "Format & Precision...". Beware, this works only with integer indicators (I8/16/32 and U8/16/32).
If the problem is to extract a bit value in a specific position, then go to the "Advanced >> Data manipulation" sub-palette where are all bit manipulation functions (rotate, shift, split...).
Don't forget either the logical functions (And, Or...) in the boolean sub-palette, where is also the "number to boolean array" function (to be used in conjunction with an index array node).
Another option is to use string conversion functions, in the "String >> String/Number conversion" sub palette.
Have a look to the attached image.

Enough ?
Chilly Charly    (aka CC)
Message 2 of 7
(4,477 Views)
trosier wrote in news:50650000000800000087000100-
1079395200000@exchange.ni.com:

> I am reading hex values from a register on my unit under test. I only
> want to monitor certain bits in the hex value to check a status. I
> have everything down to run the program except how to read my hex
> values in binary form. Any suggestions out there?

How is you value represented.



Value exist as number (I8, I16, I32, U8, U16 or U32).

In that case you can right click on the indicator and select "Format and
precision"
You can also use the "Format into string" function to get more control.
E.g: Format strings
"%08b" will show 8 bit with leading zeroes.
"%02x" will show 2 hex value with leading zeroes.



Value exist as string

In that case you can
use the "Scan from string" function.
Format strings is similar to those as the "Format into string" function.



hope this helps


--
Rolf
0 Kudos
Message 3 of 7
(4,477 Views)
Hi Trosier,

You may not need to conver the number from HEX to binary, because it may be a case of representation.. (visual)

Here's how you can check to see if your data is in the correct format.

Within the block diagram, use the wiring tool to wire indicators (right click > create > indicator) at each point where you manipulate the data (convert to hex, etc).

Go to the front panel. Right-click on the indicators and select "Format & Precision". Then select "hexadecimal". Then verify that the display is similar to that in your hex editor. It should match directly from the point where you read your file, because the binary (in it's raw visual form) is an ASCII representation of the HEX data. So display it as HEX.

That's the first step.

Aft
er you are happy that you are dealing with the correct data, you can change the type to something useful that you can manipulate. Changing type is done by TypeCasting. You take the icon and feed (left) the array. You wire the type to the top.. (and I mean wiring the type as in if you want numeric, you go into the Functions Palette under Numeric and wire the integer -0-). The output is the array in the type desired...

Let me know how it goes..

-JLV-
Message 4 of 7
(4,477 Views)
I am sorry that I have not had time to check out any of these suggestions yet being that I have had other things on my plate to do. However I have been checking to see what suggestions have been made. Maybe I have not been clear on what I have been asking or maybe I am not understanding that answers. Here is a more specific example of what I am trying to do.

I read a register on my unit under test. Lets say the register returns a 0005 hex. I am only interested in the last nibble which is 5 hex or 0101 binary. Furthermore I am only interested in bits 0 and 2 being a 1 or 0. I am just trying to take the values of those two bits and run them to a boolean indicator displaying true or false. So in short I want to take the hex value that I searched for in my
return string, change it to binary and monitor specific bits being a 1 or 0. Thanks so far for the suggestions.
0 Kudos
Message 5 of 7
(4,477 Views)
That should not be a big issue. What to you have to do is to "AND" the register value with $5 (0101), or if you need to separate bit 0 and bit 2, AND respectively with 1 (0001) and 4 (0100). Then check if the result is equal to 0 or not. Look at the attached example.

CC
Chilly Charly    (aka CC)
Message 6 of 7
(4,477 Views)
This is exactly what I need. Thanks for your reply and the example.
0 Kudos
Message 7 of 7
(4,477 Views)