Swapping the nibbles in a char element

c, c++

Solution

The nibbles (or nybbles, by analogy with byte vs bite) are 4-bit chunks of a `char`.

You can swap them with:

c = ((c & 0x0F) << 4) | ((c & 0xF0) >> 4);

Problem

What are nibbles in a char element? How do we swap them? Can anyone explain the swapping of the nibbles with an example:

Original source

Related problems