LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

rearranging bits

Solved!
Go to solution

I have the following array of binary bits

RFeng_1-1589312387915.png

 

What I want to do is take each of the bits for each of the elements and arrange them as an element for example:

as shown below the 1st 8 bits for each of the elements are arranged on array 2 as an element of 8 bits:

0 ---->00000000

0

0

0

0

0

0

0

 

RFeng_2-1589313132384.png

 

 

 

 

0 Kudos
Message 1 of 7
(2,843 Views)
Solution
Accepted by topic author RFeng

I would look at it this way.

 

Convert the numbers to a boolean array.  Do it in a loop to get a 2D array.

Transpose the boolean 2D Array.

Convert each row back to a number withing a loop.

 

Turns out it also needs to reverse the 1-D boolean arrays before and after the transpose.

I'm sure there are other ways to do this, and some may be more efficient.

 

But this works.

Message 2 of 7
(2,816 Views)

I'd call on my old buddy Type Cast Man

 

TypeCastBitsExample.png

Message 3 of 7
(2,807 Views)

That worked! Thanks.

0 Kudos
Message 4 of 7
(2,797 Views)

This also worked.  Thanks.

0 Kudos
Message 5 of 7
(2,795 Views)

Of course real programmers really hate to have green bits, because they use 8x more memory. Here's an all blue solution that works just as well. 😄

(I am sure it can be simplified further;))

 

altenbach_0-1589320186908.png

 

0 Kudos
Message 6 of 7
(2,777 Views)

@altenbach wrote:

(I am sure it can be simplified further;))

 


Plenty of alternatives. Here's another version, same result (many repetitive operations can be precalculated):

 

altenbach_2-1589323898724.png

 

 

Note that this old idea could eliminate the inner FOR loop, so please vote for it. 😄

 

 

0 Kudos
Message 7 of 7
(2,759 Views)