LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

How to combine binary arrays into one array?

Highlighted

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
(1,373 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
CLAD expired, using 2009SP1 + LV2011SP1 + LV2017 (+LV2018 sometimes) on Win7+cRIO
Kudos are welcome Smiley Wink

Message 2 of 10
(1,371 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.


LabVIEW Champion Do more with less code and in less time
0 Kudos
Message 3 of 10
(1,339 Views)

Something like this?

 

Binor.PNG

 

 

-------------------------------------------------------------------
Unfortunately, most readers of this Forum, including some real Experts, have not mastered the skill of being able to read the code that Posters fail to post. If we cannot see "what you did wrong", we are unable to tell you how to fix it. (Bob Schor 28 August 2018)
0 Kudos
Message 4 of 10
(1,317 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)


LabVIEW Champion Do more with less code and in less time
0 Kudos
Message 5 of 10
(1,308 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
(1,298 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.


LabVIEW Champion Do more with less code and in less time
0 Kudos
Message 7 of 10
(1,293 Views)

@RTSLVU wrote:

Something like this?

 

Binor.PNG

 

 


Only backwards?

 

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

 

Ben

0 Kudos
Message 8 of 10
(1,285 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 

0 Kudos
Message 9 of 10
(1,279 Views)

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

0 Kudos
Message 10 of 10
(1,260 Views)