LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Converting a numeric 2D array to binary

Solved!
Go to solution

 

I have a 2D numeric array as the output of 'Array subset' function. I need to convert the elements of each cell in this array into their binary equivalent and display them on the front panel. I am a beginner of Labview. Any  help on this is greatly appreciated. Thanks.

0 Kudos
Message 1 of 9
(3,581 Views)

Please explain what you mean by "binary equivalent".

 

What is the datatype of the array? If it is an integer (blue), all you might need is set the display format of a plain numeric array indicator to binary.

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

The array is a DBL array. I have attached a word document with my block diagram. The image below the block diagram is the output indicator on the front panel.

You can see that the output is Subnet Mask 255 255 0 0. I want to convert 255 to its binary equivalent ie. 11111111. This I need to do for the subsequent elements in the array and output the result on the front panel.

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

Your array is blue, thus definitely not DBL, only your indicator is DBL and thus mismatched. Also you "mask bits" control should be integer, you cannot have fractional masks. (right-click...representation).

 

I assume that that array is actually U8. Take the four element U8 array and typecast it to U32, then display it as %032b.

 

It would be much easier if you could attach your VI containing typical data instead of a word document with a picture. A picture never tells the full story.

0 Kudos
Message 4 of 9
(3,564 Views)

I've attached my actual VI. I've created a constant array with the mask bits and the corresponding subnet mask. This I am feeding into Array Subset function to display the Subnet mask. So when the user enters the no.of bits he wants masked, my Subnet Mask indicator would display the corresponding subnet mask in decimal format. I have to also display this subnet mask in binary like I explained before. This is where am stuck!

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

Appreciate your quick help in this regard. Thanks.

0 Kudos
Message 6 of 9
(3,543 Views)
Solution
Accepted by topic author Sures

Try this:

 

(of course you also don't really need the loopup table, because it would be trivially simple to calculate the mask from first principles;))

Message 7 of 9
(3,531 Views)

 

 

Here's a version showing a few more possibilities... pick whatever is most suitable. (notice: no more lookup table ;))

 

Download All
Message 8 of 9
(3,524 Views)

Oh that's a great solution! Your previous solution worked perfectly as well. I could complete the rest of my logic with ease! I've just started learning Labview. Your help is greatly appreciated. Thanks so much. 🙂

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