布尔逻辑中的多于运算符(逻辑门)

发布于 2024-08-23 06:49:36 字数 230 浏览 4 评论 0原文

基本上我有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

不再见 2024-08-30 06:49:36

我想过找出哪个具有最高有效位,但如果它们都相同怎么办?

从“最高有效位”一直到“最低有效位”,直到出现差异为止。第一位设置为“1”的数字最大。

为了实现这一点,请为每个数字使用一个“移位寄存器”,并为 SR 的“输出”位使用一个比较器。

I thought about finding which has the most significant bit, but what if they are both the same?

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.

浅浅 2024-08-30 06:49:36

你已经成功了。是的,从最高有效位开始。如果它们相同,则移至下一位(向右移动,向最低有效位移动)。当您发现某个位已设置(而另一个位未设置)时,即为较大的数字。

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.

找个人就嫁了吧 2024-08-30 06:49:36

确实,您走在正确的道路上。首先比较最高有效位。如果它们不相等,您就可以以一种或另一种方式输出结果。如果它们相等,则只需输出比较第二最高有效位的结果。依此类推,直到最低有效位。在某种程度上递归。在结果中,每个位都会重复相同的门配置,但最后一个除外,它会有轻微的变化(因为在该位之后没有进一步的位)。

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).

好菇凉咱不稀罕他 2024-08-30 06:49:36

如果其中一个的高位“更大”(即:它是 1,另一个是 0),那么该数字就是较大的那个。

如果它们相同,则对下一位执行相同的测试。

所以你想要类似 C 的伪代码(假装我们在数组中的位在 0 位置具有最高有效位):

// true iff x > y
(x[0] == 1 && y[0] == 0) 
|| (
  (y[0] == x[0]) 
  && (the entire expression all over again, but with [n+1] instead of [n])
)

对于你的基本情况(即:当没有更多位要测试时),使用 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):

// true iff x > y
(x[0] == 1 && y[0] == 0) 
|| (
  (y[0] == x[0]) 
  && (the entire expression all over again, but with [n+1] instead of [n])
)

For your base case (ie: when there are no more bits to test), use false or true depending on whether you want > or >=.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文