never_aditya's blog

By never_aditya, history, 23 months ago, In English

Problem Link:

Contest
Bitwise Education

Author : Dron Rahangdale
Editorialist :Aditya Gavali

DIFFICULTY:

Easy

PREREQUISITES:

Bitwise Operators , Binary System

PROBLEM:

After much effort, humanity and the residents of Pandora have achieved peace. During their interactions, the Pandora residents have expressed interest in learning about bitwise operators. Given two integers a and b. Can you provide the AND, OR, and XOR results for the integers a and b ? .

EXPLANATION:

  • Bitwise AND Operator (&) : It takes two numbers as operands and does AND on every bit of two numbers. The result of AND is 1 only if both bits are 1.
  • Bitwise OR Operator (|) : It takes two numbers as operands and does OR on every bit of two numbers. The result of OR is 1 if any of the two bits is 1.
  • Bitwise XOR Operator (^) : It takes two numbers as operands and does XOR on every bit of two numbers. The result of XOR is 1 if the two bits are different.

Example : a = 5 , b = 3
5 in binary system : 101 , 3 in binary system : 011
1. 5&3 :
(101)&(011) = 001 which is 1. So,5&3 = 1
2. 5|3 :
(101)|(011) = 111 which is 7. So,5|3 = 7
3. 5^3 : (101)^(011) = 110 which is 6. So,5^3 = 6.

Code:

Editorialist's Code(C++)

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it