04-21-2015 05:04 AM - edited 04-21-2015 05:05 AM
Hi,
I was working on decoding a binary file and one of the task is to extract out the data of varying bits from a U8 Array of fixed length. The image below is a simple illustration of this particular task.
Now, before posting you solution, I've already considered 2 methods from the forum that I've searched so far, here is the following snippet of a simple example code.
So from 2 array element of U8 data, I'm extracting out 3-, 9- and 6-bits of data from that array and place it in another array (for simplicity).
However, I believe that these 2 methods may not be efficient in terms of speed and memory performance.
I would like to know if there are other alternatives for solve this problem. If so, do share with us.
Thanks.
Regards,
Ong Ee Lim
Solved! Go to Solution.
04-21-2015 05:45 AM
04-21-2015 06:26 AM
ongeelim wrote:However, I believe that these 2 methods may not be efficient in terms of speed and memory performance.
Why? Have you measured it? Do you have a lot of data or limited time?
04-21-2015 07:04 AM
I'm with GerdW here. If you have a set block of data (8 or less blocks), read the data as a U64 and then do some bit shifting and masking with ANDs to get your data.
But looking at your two methods, you could not use the Delete From Array since that is an expensive process. Instead, use Array Subset and keep track of where you are in the array with another shift register. That would avoid some memory allocations and speed up Method 2.
04-21-2015 08:52 AM
What you really need is a bit field data type like we have in C.
So click on this link and vote (Kudos) for this LabVIEW Ideal Exchange
Provide the ability to use bit fields in clusters
04-21-2015 10:27 AM - edited 04-21-2015 10:39 AM
Hi GerdW,
Thank you for the recommendation.
I'm not working with CAN data, but rather working on the codes/functions to read a specific file type (similar to LabVIEW built-in functions to read JPEG, GIF, WAV, etc) for personal interest).
This file type will have lots of frames (Depending on the file size of the file that any user will specify).
And each frame, there will be a data block that I need to extract from which would be either 17 or 32 bytes long (Sorry if I didn't mentioned about the size of the block that I'll need to extract), depending on the situation.
Have you measured it?
I'll do the benchmarking on the code analyzing one frame later on.
Do you have a lot of data or limited time?
I would say both.
Limited time as there may be heavier computations to be done for each frame later on.
Lot of data as the initial plan is to read the whole data from a file and then analyze, rather than streaming data from disk. File size will vary depending on the file size of the file that any user will specify.
04-21-2015 11:46 AM
Yeah avoid method 1, but method 2 doesn't look terrible. There are some improvements like crossrulz mentioned, but given the task there are many worst ways to come to the same result.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
04-21-2015 08:29 PM
Hi,
Thanks for the reply, in that case, I'll just stick to the modified method 2, as described by crossrulz. Will run the benchmarking test once I get the code to analyze one frame done.
Thanks.
Regards,
Ong Ee Lim