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

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -