LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

condese array

I would like to condense an array.  The objective here is to take an array that contains 2 or more elements and condense it into one element.  For example, my 1-D array contains the elements 1000, 11, 0, 1.  I would like to condense it into the number 10001101.  I've come at this from number of directions, but have had problems.  I know it's rookie, but I just can't figure it out.  

JW
0 Kudos
Message 1 of 7
(3,737 Views)
What is the type of data in your array?  It's not clear from your description and that makes it hard to suggest a good solution.  Are those supposed to be binary values, in which case your concatenation would actually look like 1000001100000001?  Or are they strings, or decimal values?
Message 2 of 7
(3,729 Views)

Something like this?

 

 

Message Edited by Chris_VH on 03-31-2009 04:02 PM
Chris Van Horn
Applications Engineer
Message 3 of 7
(3,727 Views)
That will work for decimal values, but not for binary values.  I should have clarified, I need to do this for binary values.  U8
JW
0 Kudos
Message 4 of 7
(3,710 Views)

If what you have is an array of U8 values, and what you want is an array of U32 that packs four elements of your original array into a single element of the new array, all you need to do is typecast your array of U8 to an array of U32.  Note that this doesn't do exactly what you specified in your original question, though, because you dropped leading 0s.  If you do need those 0s removed then you'll need a more complicated solution, and a good explanation for why you'd want to do such a thing 😉

 

Message Edited by nathand on 03-31-2009 05:34 PM
0 Kudos
Message 5 of 7
(3,699 Views)

That doesn't seem to give me an array with anything in it.

 

I am talking to 4 spi chips.  Each is the same except that it is configured with a different address.  These addresses are incremental, 00, 01, 10, 00.  So I can create an array by combining a loop and two constants. A command byte should combine these elements.  1000, address, 0.   The command byte array should look like this when finished.  1000000, 1000010, 1000100, 1000110.  It should be a binary number, as that is what the driver that talks to the spi channel utilizes.

 

I will take this command byte array, and interlace it with the command array.  This will achieve an array with 8 elements.  Alternating between command byte and command. 

 

 

JW
0 Kudos
Message 6 of 7
(3,691 Views)

OK, now I think I understand what you're trying to do.  You need to take exactly 4 bits from the first array element, 2 bits from the second element, and 1 bit each from the third and fourth array elements, and combine them into a single U8 (based on the example in your initial post).  You can do this with decimate array and some math, as shown below.  Remember, though, that you need to set the radix of your array to binary in order for this to work, because there's a big difference between 10 decimal and 10 binary.  If you're going to enter these in decimal you'll have to do a lot more work to combine them.

Message Edited by nathand on 03-31-2009 08:44 PM
0 Kudos
Message 7 of 7
(3,673 Views)