### hunter_of_alts's blog

By hunter_of_alts, 3 months ago,

Hello, The main reason of newbies' fear from XOR is bad reference in the problem statements to explain XOR and other bitwise operations (Authors usually put Wikipedia reference) and newbies mostly can't understand what's XOR, today I wanna explain something about bitwise operations for this group of coders with simple language :

1- Bitwise OR :

In this operation the system compares bits in same index in binary representation and if at least one of the bits was $1$ it returns $1$ otherwise $0$, Also it is written as | in C++.

For example :

• Bitwise OR of $6$ and $3$ is :

• $6 = 110$ in binary representation and $3 = 011$.

• $6$ | $3 = 7 = (110$ | $011 = 111)$

• Note : If in any index a number doesn't have enough bits system supposes that there's a $0$ bit in that index in binary representation of that number.

2- Bitwise AND :

As it's guessable from it's name if all bits in same index were $1$ system return $1$ otherwise $0$, Also it's written as & in C++.

For example :

• Bitwise AND of $10$ and $3$ is :

• $10 = 1001$ and $3 = 0011$

• $10$ & $3 = 1 = 1001$ & $0011 = 0001$.

3- Bitwise XOR :

In this operation system compares bits in same index and if odd number of them were $1$ it returns $1$ otherwise $0$, Also it is written as xor or ^ in C++.

For example :

• Bitwise XOR of $3$ and $5$ and $8$ is :

• $8 = 1000, 5 = 0101, 3 = 0011$.

• $8$ ^ $5$ ^ $3 = 14 = 1000$ ^ $0101$ ^ $0011 = 1110$.

I hope it would be helpful for you 💗 💗 (BTW if you noticed any typo let me know).

• +14

 » 3 months ago, # | ← Rev. 2 →   +12 There are only 10 types of people...
•  » » 3 months ago, # ^ |   +40 1.those who know ternary system 2.those who doesn't know ternary system 3.those who thought this is a joke about binary system
•  » » » 3 months ago, # ^ |   +6 those who know quaternary system those who doesn't know quaternary system those who thought this is a joke about binary system people like you, who thought this is a joke about ternary system
 » 3 months ago, # |   0 If possible, could you pls attach few lists of problems based on binary operators for beginner to medium level.
•  » » 3 months ago, # ^ |   0 ++
 » 3 months ago, # |   0 Auto comment: topic has been updated by hunter_of_alts (previous revision, new revision, compare).