01-28-2010 12:08 PM - edited 01-28-2010 12:17 PM
Hi for(imstuck),
here's my try:
Incoming numbers are masked, shifted to correct position and added in a register. (Hopefully no big errors, I got the same result..)
Why do you write you're using LV7.1, when the VI comes in LV8.5???
The 2^x code part can surely be replaced by an array constant, it's just for showing concept here...
01-28-2010 12:20 PM
I'll play too.
01-28-2010 12:35 PM
GerdW wrote:
here's my try:
Why do you write you're using LV7.1, when the VI comes in LV8.5???
I noted in an earlier post to ignore my signature stating 7.1. I usually use 7.1 but in this case was given 8.5 to use and didn't bother changing my signature.
01-28-2010 01:07 PM - edited 01-28-2010 01:08 PM
Hey, can I play too? Here's my version. See if it works as expected. No guarantees. 🙂
01-28-2010 01:19 PM
01-28-2010 01:23 PM - edited 01-28-2010 01:24 PM
... slight improvement. Of course the masking should be done in U8. 😄
01-28-2010 01:46 PM
01-28-2010 03:01 PM
Altenbach, I'll take your solution. But I really had to think it through to understand it. Comments are going in my (your) code before I forget!
01-28-2010 04:25 PM
altenbach wrote:... slight improvement. Of course the masking should be done in U8. 😄
Message Edited by altenbach on 01-28-2010 11:24 AM
Here is a comment I put in my code. I figured it may be helpful if someone comes across these byte operations and has trouble figuring out what's going on. I know I did at first 🙂
Example to make the above more clear:
Lets say the U8 array's first 5 elements are 2,73,68,64,65...
The loop is set up to ignore the 2, so lets just focus on 73,68,64,65
In binary these are 1001001,1000100,1000000,1000001 respectively
63 in binary is 111111 and 7 in binary is 11. So...
Logical AND with 73 and 63 is...
1001001
AND 111111
---------------------
1001 - OR with zero = 1001, stored in shift register
Logical AND with 68 and 63 is...
1000100
AND 111111
---------------------
100
This 100 is shifted 6 bytes (becomes 100000000) and then an OR is done with what's stored
in the shift register. In this case it is 1001. The operation is below
100000000
OR 1001
--------------------
100001001
As you can see, by shifting and using an OR, this number was "prepended" to the existing number.
This method continues on until what was a byte array is now all 1's and zero's in the form of a boolean array
and can be typecast into the proper cluster
01-28-2010 06:35 PM
for(imstuck) wrote:...and 7 in binary is 11.
7 is 111 in binary.
Yes, it's easier to just skip the first elements by spinning the loop once, so we don't need to slice&dice the input array, which would require another buffer allocation in memory. The loop iterations are given by the size of the array constants.
Notice that I used a diagram constant for the typecast. Your original code (first picture you posted above) iterates over an array of clusters, causing a lot of work, even thought the data is irrelevant because we only need the type, which is the same in each iteration of your outer for loop. You are also setting yourself up for potential problems, for example if the array is too short it would limit the number of iteration of the outer FOR loop for no good reason.