There are many good answers, and some of them are technically correct.
On a larger scale, it should be understood that C / C ++ is not an assembler. The programmer's task is to try to tell the compiler about the intent that you want to achieve. The compiler will choose the best way to do this, depending on the architecture and various optimization flags.
x & = 0x0F; is the clearest way to tell the compiler what you want to achieve. If moving up and down is faster in some architecture, the job of the compiler is to know and do the right thing.
kauppi
source share