What are nibbles in a char element?
How do we swap them?
Can anyone explain the swapping of the nibbles with an example:
What are nibbles in a char element?
How do we swap them?
Can anyone explain the swapping of the nibbles with an example:
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);
int x = 0xab; // 1010 1011
int x1 = ( x & 0xF0) ; // 1010 0000
int x2 = ( x & 0x0F) ; // 0000 1011
x = ( x2 << 4 | x1 >> 4 ) ; // 1011 1010
char temp1,temp2,z;// your o/p
temp1=((x & 0x0f)<<4);//x be your input
temp2=((x & 0xf0)>>4);
z=temp1|temp2;