On 2010-01-18,
<> wrote:
> Hi,
>
> I would like to know if it is possible to mask multiple bytes at once.
> For example, if I have a char array of 5 elements, and I have a mask
> 0xFF01F7 that I would like to apply on the first 3 elements of the
> array. Is it possible to do this without comparing byte by byte, which
> I thought was quite inefficient?
>
> Thank you.
>
> Regards,
> Rayne
You can load all the bytes into an unsigned int or long (or in C99,
uint32_t or uint64_t might be safer), and then mask that.
Though to be portable across systems of different endianness you
will need to load the bytes into the integer yourself using shifts
and adds.