73. To swap nibble of a given char data ( Method 1 )
#include<stdio.h>
void
main()
{
char ch,i,j,n1,n2;
printf("To swap nibble of a given
char data \n");
printf("Enter a number : ");
scanf("%d",&ch);
for(i=7;i>=0;i--)
printf("%d",ch>>i&1);
printf("\n");
for(i=0,j=4;i<=3;i++,j++)
{
n1=ch>>i&1;
n2=ch>>j&1;
if(n1!=n2)
{
ch=ch^(1<<i);
ch=ch^(1<<j);
}
}
for(i=7;i>=0;i--)
printf("%d",ch>>i&1);
printf("\n");
}
Comments
Post a Comment