AND, OR, XOR

Bit is short for binary digit. It is one of two digits, either a ‘0' or a ‘1’. A bitwise operation operates on one or more bits. There are many types of operations that can be used on bits for example AND, OR, and XOR operations can all be used on bits.

Let’s take a look at some of these operations and see how they manipulate bits.

A bitwise ‘AND’ operation can be performed by multiplying the bits together to get the result. Another way to do this operation is if you see a 0 the result is 0 otherwise the result is 1. For example let’s AND two binary numbers together and see the result. We will use the binary numbers 1010, and 1101. 1010 is 10 in the Arabic base ten numeral system (the number system you are probably used to) , and 1101 is 13 in base 10.

Using the AND Operation example below. (NOTE: we see ‘0’ in a column, so the result of that column is 0)
1010
1101
— — -
1000

From the result above we can see that the given result is 1000 in binary which is 8 in base 10. So in conclusion 10 ‘AND’ 13 equals 8.

Next let us take a look at the ‘OR’ operation.

A bitwise ‘OR’ operation can be performed by doing boolean addition. For example 1 +0 = 1, 0 + 0 = 0, and the tricky one 1 + 1 = 1, or we can think of it as, if you see a 1 the result is a 1 otherwise the result is 0. Let us look at an example we will take the same binary numbers from before 1010 = 10 in base ten, and 1101 = 13 in base ten.

Using the OR Operation example below. (NOTE: we see ‘1’ in a column, so the result of that column is 1)
1010
1101
— — -
1111

From the result above we can see that the given result is 1111 in binary which is 15 in base 10. So in conclusion 10 ‘OR’ 13 equals 15.
Next let us take a look at the ‘XOR’ operation.

A bitwise XOR operation can be performed by the following statement;
if both bits are 0 or both bits are 1 then the result is 0 else the result is 1.
We will use the binary digits 1010 and 1101 again for this example.

Using the XOR Operation example below.
1010
1101
— — -
0111

From the result above we can see that the given result is 0111 in binary which is 7 in base 10. So in conclusion 10 ‘XOR’ 13 equals 7.

Thanks for reading this article I hope its helpful to you all ! Keep up the learning, and if you would like more computer science and algorithm analysis videos please visit and subscribe to my YouTube channels (randerson112358 & compsci112358 )

# Check Out the following for content / videos on Computer Science, Algorithm Analysis, Programming and Logic:

compsci112358:

Video Tutorials on Recurrence Relation:

Video Tutorial on Algorithm Analysis:
https://www.udemy.com/algorithm-analysis/

Written by