LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to combine binary arrays into one array?

Alright, so I've got two binary arrays. I believe one is for 20 and the other for 2. So one is 0000010100, and the other is 0000000010. These are displayed in two seperate arrays. Now I want to combine these arrays so that it comes out to: 

0000010110. First I wanted to use Insert Into Array Function, which would create a third array and insert both 1's of the first arrays into the third array. But can I also do this by just adding the binary bytes together and then making an array of that? Anyway, I have code attached. It doesn't work but was wondering if yall could take a look.

0 Kudos
Message 1 of 10
(5,166 Views)

Hi Orta,

 

why don't you OR those "arrays"? The OR is considered a "boolean add"…

 

As I don't have LV2015 available right now I cannot check your VI and can only guess what you are talking about. But still the OR operation is polymorph and can handle scalar booleans, boolean arrays and also integer (scalar and array)!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 10
(5,164 Views)

Yes, you can operate directly or the original numbers using boolean operations, no arrays needed.

However, your VI is full of race conditions because of the blatant overuse of local variables. The outcome is not predictable. Also make sure that controls have reasonable default values. Your "input array" is empty and no replacing can ever change that fact.

0 Kudos
Message 3 of 10
(5,132 Views)

Something like this?

 

Binor.PNG

 

 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 4 of 10
(5,110 Views)

As I said, you don't need arrays.

 

 

 

(Numeric display is set to %016b. You might also want to mask to 13 bits using AND, etc. so modify as needed. Make sure to use a reasonable datatype)

Download All
0 Kudos
Message 5 of 10
(5,101 Views)

Hey Altenbach, thanks for replying. But if I OR the two binaries together, would that always give the same outcome as if I inserted all the 1's from each array into a final array? But again, thanks. I'll take a look at this.

0 Kudos
Message 6 of 10
(5,091 Views)

@ShogunOrta wrote:

Hey Altenbach, thanks for replying. But if I OR the two binaries together, would that always give the same outcome as if I inserted all the 1's from each array into a final array? But again, thanks. I'll take a look at this.


Yes. Logical operations on integers are performed bitwise.

0 Kudos
Message 7 of 10
(5,086 Views)

@RTSLVU wrote:

Something like this?

 

Binor.PNG

 

 


Only backwards?

 

Arrays goof with us becuase the LSB is on the left.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 8 of 10
(5,078 Views)

You can use a "mask" to select which bits come from where.

 

In your original post you indicated the low two bits of one of the inputs determine the state of the low two bits of the result.

 

If you AND the value for the low two bits with a "3" it will mask off the higher order bits.

Do the same with the High order bits with the right maks.

 

Then OR those two intermediate results for your final answer.

 

Ben 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 9 of 10
(5,072 Views)

Just to confirm, yep, that worked fine, altenbach.

0 Kudos
Message 10 of 10
(5,053 Views)