逻辑或运算和二进制加法有什么区别? [英] what is the difference between logical OR operation and binary addition?

查看:63
本文介绍了逻辑或运算和二进制加法有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解二进制加法和逻辑 OR 表有何不同.两者都结转 1 还是如果不结转,哪个结转操作,哪个不结转?

I'm trying to understand how a binary addition and logical OR table differs. does both carry forward 1 or if not which one does carry forward operation and which does not?

推荐答案

我将尝试通过一些插图来阐明几点.

I'll attempt to clarify a few points with a few illustrations.

首先,加法.基本上就像在小学里加数字一样.但是如果你有一个 1 位与一个 1 位对齐,你会得到一个 0 和一个 1 进位(即 10,本质上类似到 5 加上 base-10 中的 5).否则,将它们添加为常规"(基数为 10)数字.例如:

First, addition. Basically like adding numbers in grade school. But if you have a 1-bit aligned with a 1-bit, you get a 0 with a 1 carry (i.e. 10, essentially analogous to 5 plus 5 in base-10). Otherwise, add them like 'regular' (base-10) numbers. For instance:

  ₁₁₁   
  1001
+ 1111
______
 11000

请注意,在最左边的列中,添加了两个 1 以得到 10,而另一个 1 得到 11(类似于5 + 5 + 5).

Note that in the left-most column two 1's are added to give 10, which with another 1 gives 11 (similar to 5 + 5 + 5).

现在,假设逻辑或"的意思是按位或(一种基本上对每对相应位执行逻辑或(包含)操作的操作),那么你有这个:

Now, assuming by "logical OR" you mean something along the lines of bitwise OR (an operation which basically performs the logical OR (inclusive) operation on each pair of corresponding bits), then you have this:

  1001
| 1111
______
  1111

只有当两个位都是 0 时,你应该有一个 0 位.

Only case here you should have a 0 bit is if both bits are 0.

最后,因为你标记了这个问题 xor,我认为它也是按位的.

Finally, since you tagged this question xor, which I assume is bitwise as well.

  1001
^ 1111
______
  0110 = 110₂

在这种情况下,两个 1 位给出 0,当然两个 0 位给出 0.

In this case, two 1-bits give a 0, and of course two 0-bits give 0.

这篇关于逻辑或运算和二进制加法有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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