Hi,
I'm trying to get two small programs that use macro to work but neither of them is doing so
the first macro selects the least significant bit from an unsigned char
#include <stdio.h>
#define LBIT(X) (((X)&1)?1:0)
int main()
{
unsigned char a;
printf("Enter a character:\n");
scanf("&c",a);
printf("Least signficant bit is %d\n",LBIT(a));
return 0;
}
I'm trying to say if x and 1 is 1 then the bit is equal to 1 otherwise it is 0, but the code is returning 1 for any character i try
the second macro selects the nth least significant bit from an unsigned char
#include <stdio.h>
#include <stdlib.h>
#define NBIT(X,N) (((X&(1<<N))?1:0)
int main()
{
unsigned char a;
unsigned int number;
printf("Enter an integer and a bit number : ");
scanf("%uc %d",&a,&number);
printf("%uc has bit %ud in position %ud\n",a,NBIT(a,number),number);
return 0;
}
this code is not even compiling
Can anyone please help me =)?
Thanks