布尔逻辑中的多于运算符(逻辑门)
基本上我有 2 个无符号 8 位二进制数,我需要使用布尔逻辑来找出哪个更大,但我无法弄清楚从哪里开始。使用逻辑门......
显然我必须分析每一位并找出哪一位更大,但如何将它们组合在一起?
假设我有 x 和 y,并且希望在 x < 时返回 true。 y(x和y是8位无符号二进制数)。我该怎么做呢?
我想过找出哪个具有最高有效位,但如果它们都相同怎么办?
有人有什么想法吗?
Basically I have 2 unsigned 8-bit binary numbers and I need to use Boolean logic to find out which is larger and I can't for the life of me figure out where to start. Using Logic gates...
Obivously I have to analyse each bit and find out which one is larger but how do I bring it all together?
Say I had x and y and wanted to return true if x < y (x and y are 8bit unsigned binary numbers). How would I go about doing this?
I thought about finding which has the most significant bit, but what if they are both the same?
Anyone got any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
从“最高有效位”一直到“最低有效位”,直到出现差异为止。第一位设置为“1”的数字最大。
为了实现这一点,请为每个数字使用一个“移位寄存器”,并为 SR 的“输出”位使用一个比较器。
You proceed from "most significant bit" down to the "least significant bit" until there is a difference. The number with the first bit set to "1" is greatest.
To implement this, use a "shift register" for each number and a comparator for the bits "out" of the SR.
你已经成功了。是的,从最高有效位开始。如果它们相同,则移至下一位(向右移动,向最低有效位移动)。当您发现某个位已设置(而另一个位未设置)时,即为较大的数字。
You're part way there. Yes, start from the most significant bit. If they are both the same, move to the next bit (moving right, towards the least-significant bit). When you find a bit that is set (and the other isn't), that is the greater number.
确实,您走在正确的道路上。首先比较最高有效位。如果它们不相等,您就可以以一种或另一种方式输出结果。如果它们相等,则只需输出比较第二最高有效位的结果。依此类推,直到最低有效位。在某种程度上递归。在结果中,每个位都会重复相同的门配置,但最后一个除外,它会有轻微的变化(因为在该位之后没有进一步的位)。
Indeed, you're on the right track. First compare the most significant bit. If they are not equal, you can already output the result, one way or the other. If they are equal, then you just output the result of comparing the second most significant bit. And so on until the least significant bit. Recursion in a way. In the result you will have the same configuration of gates repeated for each bit, except for the last one which will have a slight variation (because there is no further bit after that one).
如果其中一个的高位“更大”(即:它是 1,另一个是 0),那么该数字就是较大的那个。
如果它们相同,则对下一位执行相同的测试。
所以你想要类似 C 的伪代码(假装我们在数组中的位在 0 位置具有最高有效位):
对于你的基本情况(即:当没有更多位要测试时),使用 false或 true 取决于您是否想要 >或>=。
If the high bit of one is "bigger" (ie: it's 1 and the other one is 0), then than number is the bigger one.
If they're the same then perform the same test on the next bit.
So you want something like this C-like pseudo-code (pretending that we have the bits in arrays with the most significant in the 0 position):
For your base case (ie: when there are no more bits to test), use false or true depending on whether you want > or >=.