About Me

Wednesday, February 23, 2011

WAP to Swap Two NIbble in Byte

struct nibbles
{
int lnibble:4;
int unibble:4;
};
union swap
{
char byte;
struct nibbles nb;
};
int main()
{
union swap sw;
int temp;
sw.byte=0x12;
printf("Before swap:%x\n",sw.byte);
temp=sw.nb.lnibble;
sw.nb.lnibble=sw.nb.unibble;
sw.nb.unibble=temp;
printf("After swap:%x",sw.byte);
}

No comments:

Post a Comment

Hi thanks , we will get back to you shortly !!!