• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

Top MCQs on Bitwise Algorithms and Bit Manipulations with Answers

Question 11

What condition should be applied in the below code snippet to check whether a number is even or odd using Bitwise Operator?

C++
// C++ program to check for even or odd
// using Bitwise operator
#include <iostream>
using namespace std;

// Returns true if n is even, else odd
bool isEven(int n)
{

    if (______)
        return 0;
    return 1;
}

// Driver code
int main()
{
    int n = 10;
    isEven(n) ? cout << "Even" : cout << "Odd";
    return 0;
}
  • n | 2

  • (n & 1 ==1)

  • n>>1

  • n<<1

Question 12

What will be the output of the following code for N=128?

C++
int function(unsigned n)
{
	if (!isPowerOfTwo(n))
		return -1;

	unsigned i = 1, pos = 1;
	while (!(i & n)) {
		i = i << 1;
		++pos;
	}

	return pos;
}
  • -1

  • 1

  • 64

  • 8

Question 13

What will the below code do?

C++
void bin(unsigned n)
{
    if (n > 1)
        bin(n / 2);

    cout << n % 2;
}
  • reverse the bits of a number

  • invert the bits of a number

  • print the binary representation of a number

  • None

Question 14

What is a Single Operand Operator below.?

  • & Bitwise AND Operator 
     

  • ~ Bitwise Negate Operator

  • ^ Bitwise Exclusive OR

  • | Bitwise OR operator

Question 15

Suppose we have a set {1,  2, 3}. Find the XOR of all the subsets of the set.

  • 1

  • 2

  • 3

  • 0

Question 16

Which bitwise operator is used to swap two numbers?

  • Left Shift(<<)

  • Right shift(>>)

  • Bitwise OR |

  • Bitwise XOR ^

Question 17

What will the do the below code snippet?

C++
const int x = 32; 
  
char *function(char *a) 
{ 
    for (int i=0; a[i]!='\0'; i++) 
        a[i] = a[i] & ~x; 
  
    return a; 
} 
  • convert the characters into integers.

  • Convert the character into a binary number

  • convert the characters into uppercase letters.

  • All of these

Question 18

What are we doing in the below code snippet?

C++
 unsigned int function(int n)
    {
        unsigned int count = 0;
        while (n) {
            n &= (n - 1);
            count++;
        }
        return count;
    }
  • finding the number of set bits present in the n.

  • finding the count of 0's in n.

  • Both A and B

  • None

Question 19

What will do the below code?

C++
bool fun(int x, int y)
{
	return ((x ^ y) < 0);
}

Question 20

By using which Bitwise operator, we can find the square of a number?

123

There are 30 questions to complete.

Last Updated :
Take a part in the ongoing discussion

Trending in News

View More