Macro to swap nibble of BYTE source code

This snippet submitted by T Sailesh on 2006-06-08. It has been viewed 5043 times.
Rating of 5.4 with 10 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);

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




More C and C++ source code snippets

Add a snippet!