翻转位的位掩码...没有异或?
真的很简单。我想对一个以 2 的补码表示的整数取反,为此,我需要首先翻转字节中的所有位。我知道使用 XOR 很简单——只需将 XOR 与位掩码 11111111 一起使用即可。但是如果不使用 XOR 呢? (即只是“与”和“或”)。哦,在我使用的这种蹩脚的汇编语言中,NOT 不存在。所以那里也没有骰子。
Pretty simple, really. I want to negate an integer which is represented in 2's complement, and to do so, I need to first flip all the bits in the byte. I know this is simple with XOR--just use XOR with a bitmask 11111111. But what about without XOR? (i.e. just AND and OR). Oh, and in this crappy assembly language I'm using, NOT doesn't exist. So no dice there, either.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法用“与”门和“或”门构建“非”门。
正如我被要求解释的那样,这里的格式很好。假设您有任意数量的
AND
和OR
门。您的输入是A
、0 和 1。您有六种可能性,因为您可以从三个信号(选择一个省略的)和两个门中生成三对。现在:因此,在您将任何信号输入第一个门之后,您的新信号集仍然只是 A、0 和 1。因此,这些门和信号的任何组合都只会得到 A、0 和 1。如果您的最终输出是 A,那么这意味着对于 A 的两个值来说,它不会等于 !A,如果您的最终输出是 0 那么 A = 0 是这样一个值,即您的最终值与 1 的 !A 不同。
编辑:单调的评论也没错!让我在这里重复一遍:如果将 AND / OR 的任何输入从 0 更改为 1,那么输出不会减少。因此,如果你声称构建一个非门,那么我会将你的输入从 0 更改为 1 ,你的输出也不会减少,但它应该减少——这是一个矛盾。
You can't build a NOT gate out of AND and OR gates.
As I was asked to explain, here it is nicely formatted. Let's say you have any number of
AND
andOR
gates. Your inputs areA
, 0 and 1. You have six possibilities as you can make three pairs out of three signals (pick one that's left out) and two gates. Now:So after you fed any of your signals into the first gate, your new set of signals is still just A, 0 and 1. Therefore any combination of these gates and signals will only get you A, 0 and 1. If your final output is A, then this means that for both values of A it won't equal !A, if your final output is 0 then A = 0 is such a value that your final value is not !A same for 1.
Edit: that monotony comment is also correct! Let me repeat here: if you change any of the inputs of AND / OR from 0 to 1 then the output won't decrease. Therefore if you claim to build a NOT gate then I will change your input from 0 to 1 , your output also can't decrease but it should -- that's a contradiction.
(foo & ~bar) | 是否(~foo & bar)
能做到这一点吗?编辑:哦,NOT 不存在。没看到那部分!
Does
(foo & ~bar) | (~foo & bar)
do the trick?Edit: Oh, NOT doesn't exist. Didn't see that part!