Reputation: 141
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?
Upvotes: 2
Views: 4659
Reputation: 3294
I'll attempt to clarify a few points with a few illustrations.
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
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
Only case here you should have a 0
bit is if both bits are 0
.
Finally, since you tagged this question xor
, which I assume is bitwise as well.
1001
^ 1111
______
0110 = 110₂
In this case, two 1
-bits give a 0
, and of course two 0
-bits give 0
.
Upvotes: 2
Reputation: 23837
With a logical OR you get a logical result (Boolean). IOW true OR true is true (anything other than false OR false is true). In some languages (like C) any numeric value other than 0 means true. And some languages use an explicit datatype for true, false (bool, Boolean). In case of binary OR, you are ORing the bits of two binary values. ie: 1 (which is binary 1) bitwise OR 2 (which is binary 10) is binary 11:
01
11
which is 3. Thus binary OR is also an addition when the values do not have shared bits (like flag values).
Upvotes: 0
Reputation: 1234
The exclusive-or (XOR) operation is like binary addition, except that there is no carry from one bit position to the next. Thus, each bit position can be evaluated independently of the rest.
Upvotes: 4