Question 1
Which bitwise operator is used to swap two numbers?
Left Shift(<<)
Right shift(>>)
Bitwise OR |
Bitwise XOR ^
Question 2
What is the output of the below code for input num = 15?
unsigned int fun(unsigned int n)
{
unsigned int count = 0;
while (n) {
count += n & 1;
n >>= 1;
}
return count;
}
unsigned int fun(unsigned int n) {
unsigned int count = 0;
while (n) {
count += n & 1;
n >>= 1;
}
return count;
}
public class Main {
public static int fun(int n) {
int count = 0;
while (n != 0) {
count += n & 1;
n >>= 1;
}
return count;
}
}
def fun(n):
count = 0
while n:
count += n & 1
n >>= 1
return count
function fun(n) {
let count = 0;
while (n) {
count += n & 1;
n >>= 1;
}
return count;
}
15
5
4
3
Question 3
Which is the format specifier used to prefix 0x and print a number in hexadecimal notation.?
%O
%#
%x
%#x
Question 4
Which is the Bit Toggling operator below.?
Bitwise OR operator( | )
Bitwise XOR Operator (^)
Bitwise AND Operator(&)
TILDE operator(~)
Question 6
Bitwise & can be used in conjunction with ~ operator to turn off 1 or more bits in a number.
True
False
Question 7
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 8
Predict the output:
#include <iostream>
using namespace std;
int main()
{
int x = -5;
x = x >> 1;
cout << x << endl;
return 0;
}
#include <stdio.h>
int main() {
int x = -5;
x = x >> 1;
printf("%d\n", x);
return 0;
}
public class Main {
public static void main(String[] args) {
int x = -5;
x = x >> 1;
System.out.println(x);
}
}
# x is initialized to -5
x = -5
# Right shift operation
x = x >> 1
# Print the result
print(x)
// x is initialized to -5
let x = -5;
// Right shift operation
x = x >> 1;
// Print the result
console.log(x);
-2
-3
Error
-1
Question 9
What is the output of the below code?
#include <bits/stdc++.h>
using namespace std;
int main()
{
if (~0 == 1)
cout << "Yes";
else
cout << "No";
}
#include <stdio.h>
int main() {
if (~0 == 1)
printf("Yes");
else
printf("No");
return 0;
}
public class Main {
public static void main(String[] args) {
if (~0 == 1)
System.out.println("Yes");
else
System.out.println("No");
}
}
if ~0 == 1:
print("Yes")
else:
print("No")
if (~0 === 1)
console.log("Yes");
else
console.log("No");
Yes
No
Error
None
Question 10
What will the below code do?
void function(int& num, int pos)
{
num |= (1 << pos);
}
void setBit(int* num, int pos) {
*num |= (1 << pos);
}
void setBit(int[] num, int pos) {
num[0] |= (1 << pos);
}
def set_bit(num, pos):
return num | (1 << pos)
function setBit(num, pos) {
return num | (1 << pos);
}
divide num by pos.
Multiply num by pos.
Add num with pos.
set the given position (pos) of a number (num).
There are 30 questions to complete.