c - Using bitwise operators ~ and & to make | Operator -
i've got solve task can't find answer:
compute x | y using ~ , &
maximum allowed operations 8
edit: in twos complement , 32-bit representations of integers. right shifts performed arithmetically.
by looking @ truth table of x | y see:
0 | 0 = 0 0 | 1 = 1 1 | 0 = 1 1 | 1 = 1 x | y 1 if bothx , y not 0. can translate ~(~x & ~y):
~(~0 & ~0) = ~(1 & 1) = ~1 = 0 ~(~0 & ~1) = ~(1 & 0) = ~0 = 1 ~(~1 & ~0) = ~(0 & 1) = ~0 = 1 ~(~1 & ~1) = ~(0 & 0) = ~0 = 1
Comments
Post a Comment