二进制运算以从结果值获取操作数 [英] binary operation to get operands from result value

查看:108
本文介绍了二进制运算以从结果值获取操作数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

x& y = R,其中&"是按位AND运算符
那么如何使用值R和y获得值x?

x & y =R where ''&'' is a bitwise AND operator
then how do I get a value x using values R and y?

推荐答案

这是不可能的.例如,考虑以下情况:

It is not possible. For example, consider the following case:

x=0110 //will be unknown
&
Y=0101
=====
R=0100



您可以恢复除#1和#3之外的所有位,其中已知操作数的位和结果位都为0.在这种情况下,第一个(未知)操作数的位可以为0或1,因此不会影响结果位.在此示例中,x可以为1110、0110、1100或0100.

—SA



You can restore all bits except bits #1 and #3, where both the bit of known operand and a bit of result are both 0. In this case, the bit of the first (unknown) operand can be either 0 or 1, it would not affect the result bit. In this example, x can be 1110, 0110, 1100 or 0100.

—SA


您不能-并且丢弃"信息.
如果您具有二进制值101和110,并且将它们与在一起,则得到二进制结果100.从该结果中,您可以说X和Y都是集合{100,101,110,111}的成员-如果仅涉及三个位-但是您不能说哪个值分配给了哪个变量.
You can''t - AND "throws away" information.
If you have the binary values 101 and 110, and you AND them together, you get the binary result 100. from that result you can say that both X and Y are members of the set { 100, 101, 110, 111 } - if there are only three bits involved - but you cannot say which value was assigned to which variable.


通常来说,您不能.
例如,假设y=0,然后是R=0,而与x的值无关.
另一方面,如果y的所有位都已置1,那么您将拥有关于x的完整信息,因为x=R.
换句话说:
  • 如果设置了y 的某个位(等于1),则x 的相应位等于R的相应位
  • 如果 y 的某个位被重置(等于0),则R不会提供有用的信息,而相应的位x可以是10.
Generally speaking you cannot.
Suppose, for instance, y=0, then R=0 regardless of the value of x.
On the other hand, if all bits of y are set then you have full info about x, since x=R.
In other words:
  • if a bit of y is set (equal to 1) then corrensponding bit of x is equal to the corresponding bit of R.
  • if a bit of y is reset (equal to 0) then R provides no useful info and the corrensponding bit of x may be either 1 or 0.


这篇关于二进制运算以从结果值获取操作数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆