What is the reverse operation of bitwise AND?

∥☆過路亽.° 提交于 2019-12-24 09:04:01

问题


How can I get a from b and c? What would be the reverse operation?

Here is the code:

class  s
{
    public static void main(String ar[])
    {

        int a = 20;

        int b = 5;

        int c = 0;

        c = (a & b) ;

        System.out.println(c);

        int d = (c & b);

        System.out.println(d);
    }
}

回答1:


You can't. If a bit in c is 0 and the corresponding bit in b is 0, it's impossible to know whether the corresponding bit in a was 0 or 1. By a similar argument, bitwise OR (the | operator) is also irreversible. On the other hand, bitwise XOR (the ^ operator) is reversible.




回答2:


If you look at the truth table of the and logical operation, you can see that it contains three falses and one true. Therefore it can't be reversed.

Only equals and xor have balanced truth tables, and they are the two reversible boolean operators.



来源:https://stackoverflow.com/questions/5330520/what-is-the-reverse-operation-of-bitwise-and

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!