Swap two nibbles in a byte | GeeksforGeeks
A nibble is a four-bit aggregation, or half an octet. There are two nibbles in a byte.
Given a byte, swap the two nibbles in it.
The expression “x & 0x0F” gives us last 4 bits of x.
The expression “x & 0xF0” gives us first four bits of x.
Read full article from Swap two nibbles in a byte | GeeksforGeeks
A nibble is a four-bit aggregation, or half an octet. There are two nibbles in a byte.
Given a byte, swap the two nibbles in it.
unsigned
char
swapNibbles(unsigned
char
x)
{
return
( (x & 0x0F)<<4 | (x & 0xF0)>>4 );
}
The expression “x & 0x0F” gives us last 4 bits of x.
The expression “x & 0xF0” gives us first four bits of x.
Read full article from Swap two nibbles in a byte | GeeksforGeeks