LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

radio button position to hex

Solved!
Go to solution

I have a Radio Button Control set to allow No Selection and that has 10 radio buttons each representing a position of a switch. I am using a Radio Button Control because at most only one switch position can be active at a time.

 

I want to convert the selection to a hex value. For example, if radio button1 is selected, then the value is 0x1. If radio button 10 is selected then 0x20.

 

So far I have code checking to see if the value of the Radio Button Control is 0 (=no selection) or not. If there is a selection I am using a Rotate. Is there another way to do this that is more efficient?

 

 

 

 

0 Kudos
Message 1 of 9
(3,293 Views)
Solution
Accepted by topic author nyc_(is_out_of_here)

Create an array constant of your hex values (I guess just U8 with the display set to hexadecimal, or whatever datatype you want, string, etc.).

The first element is "no selection" and so on.

 

Now use "index array" and wire the radiobutton control to the index terminal. Wire the array constant to the array input.

 

The output of "index array" will be your desired value.

0 Kudos
Message 2 of 9
(3,291 Views)

Thank you. Sometimes, lookup tables are the way to go.

 

 

0 Kudos
Message 3 of 9
(3,277 Views)

I had the very identical need a while back.

I offer another way to "skin the cat".

 

RadioButton2Hex.png

 

The only other case is passing the zero straight though.

Omar
0 Kudos
Message 4 of 9
(3,261 Views)

Ah!  I like this solution too.

 

I wasn't sure whether using the Rotate is more processor-intensive than some other method I hadn't thought of before.

 

 

 

0 Kudos
Message 5 of 9
(3,255 Views)

I wasn't quite sure how regular your pattern is and what output data you want, thus the suggestion for a LUT. (HEX is too generic a description ;))

 

I don't understand the need for rotate, shouldn't a shift be more appropriate (or simply scale by powers of two, which is internally also just a shift in the case of integers)

 

Here's what I would do.

 

0 Kudos
Message 6 of 9
(3,243 Views)

I thought of the scale by powers of two as well.

 

I will use the Shift instead of the Rotate since I won't be needing that capability with the case statement as you have it.

 

 

0 Kudos
Message 7 of 9
(3,218 Views)

The "shift" and "scale by power of two" are identical and fully interchangeable for integer inputs. Pick one. 😉

 

I think in general you need the case statement if you allow "no selection" for the radiobutton. Please double-check, maybe you are lucky and it gets masked off because you ignore certain higher bits. 😉

0 Kudos
Message 8 of 9
(3,214 Views)

Yes, I do need the Case statement.

 

I learned something new.

 

 

 

0 Kudos
Message 9 of 9
(3,207 Views)