• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

Top MCQs on Bitwise Algorithms and Bit Manipulations with Answers

Question 21

What will the output of the following code for N = 5 and K =2?

C++
bool function(int n, int k)
{
    bool bit = n & (1 << k);
    return bit;
}
 
  • 0

  • 2

  • 5

  • 1

Question 22

What will the below code do?

C++
void function(int& num, int pos) 
{
   num |= (1 << pos); 
}
  • divide num by pos.

  • Multiply num by pos.

  • Add num with pos.

  • set the given position (pos) of a number (num).

Question 23

What is the output of the below code?

C++
#include <bits/stdc++.h>
using namespace std;
int main()
{
    if (~0 == 1)
        cout << "Yes";
    else
        cout << "No";
}
  • Yes 

  • No

  • Error

  • None

Question 24

Predict the output:

C++
#include <iostream>
using namespace std;

int main()
{
    int x = -5;
    x = x >> 1;
    cout << x << endl;
    return 0;
}
  • -2

  • -3

  • Error

  • -1

Question 25

If we have to add two numbers without having any carry, which bitwise operator should be used?

  • Bitwise OR |

  • Bitwise AND &

  • Bitwise NOT ~

  • None

Question 26

Bitwise & can be used in conjunction with ~ operator to turn off 1 or more bits in a number.

  • True

  • False

Question 27

What is the output of the below expression? 

000111 | 01010
  • 0000000

  • 00

  • 010111

  • None

Question 28

Which is the Bit Toggling operator below.?

  • Bitwise OR operator( | )

  • Bitwise XOR Operator (^)

  • Bitwise AND Operator(&)

  • TILDE operator(~)

Question 29

Which is the format specifier used to prefix 0x and print a number in hexadecimal notation.?

  • %O

  • %#

  • %x

  • %#x

Question 30

What is the output of the below code for input num = 15?

C++
unsigned int fun(unsigned int n)
{
    unsigned int count = 0;
    while (n) {
        count += n & 1;
        n >>= 1;
    }
    return count;
}
  • 15

  • 5

  • 4

  • 3

There are 30 questions to complete.

Last Updated :
Take a part in the ongoing discussion

Trending in News

View More