Macro to swap nibble of BYTE source code

This snippet submitted by T Sailesh on 2006-06-08. It has been viewed 18804 times.
Rating of 5.4 with 98 votes

#define _swapNibble(x) ((x<<4)|(x>>4))

int main()
    // On executing you will get
    // x before swap = 0x1c
    // x after swap = 0xc1
    char x = 0x1c;
    printf("x before swap = %x\n",x);

    printf("x afer swap = %x",x);

More C and C++ source code snippets