# Four Different Characters

I suddenly got an example that may help you remember the characteristics of AND, OR, NOT and XOR. Consider them as four different human individuals, with four different characteristics or behavior. Humans generally have the behavior of conveying things different from what they really heard; they may add something to the original story or hide something or even tell opposite of what happened. We have had lots of acquaintances with situations like this which would make this example unforgettable I think. Our men, AND, OR, NOT and XOR are no exception to these characters but each one having a different unique character.

Whenever AND conveys something that he had already heard, he has the character of hiding something from the original story or incident. If he wishes, he can tell everything exactly without hiding anything too.

Let S be the story and W be the wish (which part of the story he wants to hide and which one to tell).

``````AND :

S     => XXXX XXXX
W     => 0011 1100
---------
S & W => 00XX XX00
``````

This process is technically called as masking and the wish is called as mask. Wherever 1 is present, the original input is passed through and if 0, the original input is blocked (the story is hidden).

Now OR, whenever he conveys something that he had already heard, he has the character of adding something to the original story or incident.

``````OR :

S     => XXXX XXXX
W     => 0011 1100
---------
S | W => XX11 11XX
``````

This is used to set a particular bit in a bitfield.

NOT is a pure liar. He tells everything opposite to what he heard. Notably he doesn’t have any ‘wish’ other lying. It gives the complement of each bit.

``````NOT :

S     => XXXX XXXX
---------
____ ____
~S     => XXXX XXXX
``````

XOR is a clever liar. He can lie when he wants to lie and tell truth where he wants to tell truth. But remember, he cannot hide or add something to the original story he heard.

``````XOR :

S     => XXXX XXXX
W     => 0011 1100
---------
__ __
S^W   => XXXX XXXX
``````

Wherever 1 is present, the equivalent bit at S is complemented and if 0 is present the bit is passed as such. XOR has great importance in the field of Cryptography. Moreover It has many other interesting applications too.

Try to use these operators as much as you can in your programs and try to master them. That will really help you much. If you have found anything on your own or programmed on your own regarding bitwise, write to my mail id. I’ll be glad to learn that. Sooner, I’ll try to catch up with you with a new article.