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 each the opposite of the lower four bits of y (x has a 0 where y has a 1 and vice versa). [Note that this compiler doesn\'t accept binary constants , so use hexidecimal instead. I.e., for 0b00111111 use 0x3F.]
Solution
expression: if(((x^y)*16) == 0xF0)
all the bits in x^y are 1\'s if each bits in x and y are compelement to each other, but we need to check only last 4 bits.
Hence, (x^y)*16, will shift the bits on the right side. Hence, last 4 bits are all 1\'s then answer should be F0.
