Als wrote:
>
> What's an efficient way to mask a last 3 bits of a 8-bit char and make them
> all zero?
>
> Bit-shifting is possible but not sure if it is efficient enough.
>
> Example:
>
> 01011[010] --> 01011[000]
Many or perhaps even most C implementations use an
eight-bit `char', but that is not actually guaranteed
by the language, and implementations using wider `char'
are known to exist. Still:
unsigned char byte = 0x5A; /* 00...01011010 */
byte &= ~ 0x07; /* AND with 11...11111000 */
/* result: 00...01011000 */
Also, the Standard says nothing about the relative
efficiency of operations in C. In fact, *you* haven't
said what you mean by "efficiency!" Do you want minimal
code size, minimal register usage, minimal execution
time, minimal debugging time ...?
--