Assume that x and y are already defined as being of type cha
Assume that x and y are already defined as being of type char . Write a single expression that will return true if the lower four bits of x are the same as the lower four bits of y. [Note that this compiler doesn\'t accept binary constants , so use hexidecimal instead. I.e., for 0b00111111 use 0x3F.]
Solution
#include <stdio.h>
int main()
{
unsigned char x = 10;
unsigned char y = 20;
char xbits = x&0x0f; //extracting lower four bits
char ybits = y&0x0f;
printf(\"\ x = %x\",xbits);
printf(\"\ y = %x\",ybits);
if( (x&0x0f) == (y&0x0f) )
printf(\"\ The lower four bits of chars are equal\");
else
printf(\"\ The lower four bits of chars are not equal\");
return 0;
}
Output:
Success time: 0 memory: 2168 signal:0
