So how do you exactly do this ????
A function that zeroes the upper 4 bits of an unsigned char x and inverts its lower 4
bits.
EG : 170 binary is 10101010
Then result : 00000101
I managed until 00001010, but i unable to do the inversion to 00000101. Need urgent help, i'm going crazy with this lab tutorial ....
Code:
#include <stdio.h>
main()
{
int i,c;
unsigned int a, b[8];
printf("\nEnter a decimal value: ");
scanf("%d",&a);
c=a;
for(i=0;i<=7;i++)
{
b[i]=c%2;
c=c/2;
}
printf("\nInput %d is ",a);
for(i=7;i>=0;i--)
{
printf("%d",b[i]);
}
printf(" in binary.\n\n");
for(i=7;i>=4;i--)
{
b[i] = b[i] >> 1;
}
printf("Result :");
for(i=7;i>=0;i--)
{
printf("%d", b[i]);
}
getchar();
getchar();
}