逻辑运算符 'A 并不意味着 B'使用 AND、OR、XOR 运算符
我有两个位掩码(例如 A 和 B,我想知道 A 的哪一位为 1,其中对应的 B 位为 0(反之亦然)。
当然,这可以使用条件语句来实现,但我不想迭代/移位来测试位掩码的所有位,但
我需要的逻辑条件未实现(或者至少,我看不到它)。使用与逻辑门的并行,我需要运算符“A 不暗示 B”(请参阅 Wikipedia)。
是否可以使用 AND、OR、XOR 运算符来实现此类运算符?
I have two bit masks (say A and B, and I want to know which bit of A is 1 where the corresponding B bit is 0 (and viceversa).
Of course this is implementable using conditional statements, but I don't want to iterate/shift for testing all bits of the bit mask.
The logic condition which I need is not implemented (or at least, I can't see it). Using a parallel with the logic gates, I need the operator 'A doesn't imply B' (see on Wikipedia).
Is it possible to implement such operator using AND, OR, XOR operators?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据链接的维基百科,最简单的表达式是
A and (not B)
According to the linked Wikipedia, the simplest expression is
A and (not B)
您可以使用:
A xor(不是B)分析:
编辑:
将其更改为简单的XOR,给出问题要求的结果。也许问题的措辞不正确,因为解决方案似乎太简单了......
You can use:
A xor (not B)Analysis:
Edit:
Changed it to a simple XOR, that gives the result that the question asks for. Perhaps the question is not correctly worded, as the solution seems too simple...
我会说:
给你一个 1,其中 A 是 1,B 是 0。
首先你检测 A 和 B 不同的地方,然后匹配 A 是 1 的地方。
I would say:
gives you a 1 where A is 1 and B is 0.
First you detect where A an B are different, then you match with where A is 1.