I have a C array like:
char byte_array[10];
And another one that acts as a mask:
char byte_mask[10];
I would like to do get another array that is the result from the first one plus the second one using a bitwise operation, on each byte.
What’s the most efficient way to do this?
thanks for your answers.
This will work for all arrays and processors. However, if you know your arrays are word-aligned, a faster method is to cast to a larger type and do the same calculation.
For example, let’s say
n=16instead ofn=10. Then this would be much faster:(Of course you need a proper type for
uint32_t, and ifnis not a power of 2 you need to clean up the beginning and/or ending so that the 32-bit stuff is aligned.)Variation: The question specifically calls for the results to be placed in a separate array, however it would almost certainly be faster to modify the input array in-place.