I've checked the questions that were already posted and couldn't quite find the solution to my problem...
I'm making a console program that inputs 2 variables: 1 is a byte and the other is a number of the bit I need to get from that byte using only masking and if statements.
int E1 () {
unsigned char a, b, c;
printf("Number (byte):");
scanf("%d", &a);
a= (unsigned char)a;
printf("\n Bit you want to output (between 0 and 7) :");
scanf("%d", &b);
b=(unsigned char)pow((float)2.0,b);
printf("Mask is: %d", b);
c= a & b; //<-- This returns 0
if (c>0) {
printf("\n\nThe bit is: 1");
}
else {
printf("\n\nThe bit is: 0");
}
return 0;
}
I've asked my teacher and he said that it should work fine. I've tried it and it doesn't work. He is using Visual Studio Express, the free version one can get from Microsoft website and I'm using Code::Blocks (in case this makes a difference in the results).I've added a comment to where I think the problem lies but not sure.
Can anybody please help me with this. Thanks in advance.