01-27-2010 01:49 PM - edited 01-27-2010 01:52 PM
Below is a screenshot of my block diagram. I keep thinking there must be an easier way to fill the cluster values other than using those two nested for loops but I can't think of one. I am taking 4 rows from a byte array and filling cluster elements 0-5 with 6 bits from row 0, cluster elements 6-12 with six bits from row 1, cluster elements 13-18 with 6 bits from row 2, and then the final 3 cluster elements with 3 bits from row 3. Any suggestions or is this the best way? I seem to think there must be something more simple. I could see this ending up in the rube goldberg section easily 🙂
Solved! Go to Solution.
01-27-2010 03:29 PM
Only some minor improvements:
* Use the arrray subset before converting the [U8] to 2D-boolean array (increased performance). OR: remove it completely and use the index array [0,6,6,6,3] (for loop stops when one of the auto-indexing arrays is empty).
*In you inner for loop, use the autoindexing of the boolean array instead of the Index-Array.
Felix
01-27-2010 08:01 PM
01-28-2010 01:50 AM
Correct me if i'm wrong, but the whole inner structure is basically 4 AND-operations? If so, after your String-to-U8 you can do a AND with 31,31,31,7.
/Y
01-28-2010 03:22 AM
01-28-2010 03:48 AM
Yamaeda wrote:Correct me if i'm wrong, but the whole inner structure is basically 4 AND-operations? If so, after your String-to-U8 you can do a AND with 31,31,31,7.
I don't think so. The number of bits appended to the array is variable between iterations of the innermost loop. A plain AND would pad all segments to the same number of bits and would produce a different result.
In the shown code, the final boolean array will have 21 elements. You cannot get that with 4 plain AND operations.
01-28-2010 04:12 AM
"I am taking 4 rows from a byte array and filling cluster elements 0-5 with 6 bits from row 0, cluster elements 6-12 with six bits from row 1, cluster elements 13-18 with 6 bits from row 2, and then the final 3 cluster elements with 3 bits from row 3."
altenbach wrote:I don't think so. The number of bits appended to the array is variable between iterations of the innermost loop. A plain AND would pad all segments to the same number of bits and would produce a different result.
In the shown code, the final boolean array will have 21 elements. You cannot get that with 4 plain AND operations.
Well no, not 4 plain ANDs.
Looking at the function and elaborating: For each character recieved he selects the first 4 converted to a boolean array. From this array the first X according to the array is selected and added to an output array. The question is ofc why a long boolean array is used at all. The function of selecting the X can be done by an AND and the building of the "array" can be done by bitshifting (by the same X), so it all can be the 21 first bits of a normal INT.
(i know you like those bit operations) 😉
/Y
01-28-2010 10:00 AM
I'll post the VI later I have to get some stuff done first. Thanks for the responses.
01-28-2010 10:27 AM
Yamaeda wrote:(i know you like those bit operations) 😉
Originally, you said "... but the whole inner structure is basically 4 AND-operations? If so, after your String-to-U8 you can do a AND with 31,31,31,7." I am just pointing out that there us (much) more to it than that. 😮
Don't misunderstand me, I do think the code is way too complicated and I truly believe there should NOT be any green arrays at all (except maybe at the very end where it is then truncated to 21 elements). Everything could be accumulated in a single scalar U32, (for example) using some succesive bitshifting and simple bitwise operations.
We really need some code containing typical 19 byte string data and the expected result, so hopefully we'll get that soon. The posted code is ambiguous, because the exact datatype of the clusters is not shown. 🙂
01-28-2010 10:50 AM - edited 01-28-2010 10:52 AM
Here ya go. You guys are getting antsy!
Ignore my signature this is in v8.5
I only had a byte array constant I had saved as sample data. I don't have access to the hardware right now so I can't get the actual string it returns, but I guess that can be figured out with an ascii chart and the byte array I have given(or if you really want to stick with labview, FLATTEN TO STRING!). Hopefully it wont be an issue though.