bit manipulation - Manipulating Bit-wise Operations -


there puzzle question of creating equivalent bit-wise & | , ~ operators.

i've been doing brute force combinations of | , ~ using 6 (0110) , 5 (0101) trying 4 (0100), still cannot answer.

the maximum number of operation can used 8.

can please give me hints?

what helps here de morgan's law, says:

~(a & b) == ~a | ~b 

thus can negate , get:

a & b == ~(~a | ~b)     //4 operations 

and looking @ truth table (and in fact, god bless simplicity of binary logic, there 4 possible combintations of inputs generate appropriate outputs for) can see both equivalent (last 2 columns):

a | b | ~a | ~b | ~a or ~b | ~(~a or ~b) | , b --|---|----|----|----------|-------------|-------- 0 | 0 |  1 |  1 |     1    |      0      |    0 1 | 0 |  0 |  1 |     1    |      0      |    0 0 | 1 |  1 |  0 |     1    |      0      |    0 1 | 1 |  0 |  0 |     0    |      1      |    1 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -