For example,
if (input & 1 << IN_FLAG_NUMBER)
output |= 1 << OUT_FLAG_NUMBER
... where IN_FLAG_NUMBER and OUT_FLAG_NUMBER are not the same.
An example of where this might be done is where if the PARODD bit in the
termios structure is set, set the appropriate bit in the UART's MCR
register.
The naive implementation, either involving an if statement or the C
conditional operator (i.e., "output |= (input & 1 << IN_FLAG_NUMBER) ?
(1 << OUT_FLAG_NUMBER) : 0") both involve an assembly language
conditional jump instruction, which is expensive, because it involves
pipeline stalls, etc.
Colin has proposed a macro which plays shifting and masking games which
is much faster.
- Ted