378 views
1 votes
1 votes

Problem Statement: Class teacher to IX-C wants to store whether a particular student has passed in exams. The class has a strength of $32$ students. Their roll numbers lie in the range: $[1, 32]$. The teacher used bits of an integer to store the information. This integer is called storage integer. Set bit or bit with value $1$ of this storage integer denotes that the student has passed and vice versa for unset bit.

Question: The class teacher has to conduct an advanced exam. Only students who have passed this exam will be eligible for the advanced exam. Now, the seating arrangement has been made with VII-C, which also has the same strength of $32$ students. The seating arrangement is to be made in such a way that roll number one of IX-C and VII-C have to sit together, similarly for roll number two and so on. If roIl number one of IX-C is ineligible, then VII-C student will sit alone.

If the storage integer of both the classes is given to you, then which of the following operators will you use to find the count of students that are sitting in pairs.

Options: Pick one correct answer from below

a. Apply Bitwise XOR (^) operator and count number of unset bits

b. Apply Bitwise NOT (~) operator and count number of set bits

c. Apply Bitwise OR (|) operator and count number of set bits

d. Apply Bitwise AND (&) operator and count number of set bits

2 Answers

1 votes
1 votes
Option d) AND operator
if both students from the corresponding classes are ineligeble , 0AND0 =0 , not counted
any one student ineligeble , 0AND1 or 1AND0 =0 not counted
only 1AND1=1 is counted , so we AND both the integers and count the no of set bits
0 votes
0 votes
Same as the number of set bits in the original 32 bit number, that defines the passing/failing status of the IX-C students.

Because only their passing/failing status matters in determining if sitting will be in pairs or single.

 

Related questions

1.2k
views
5 answers
3 votes
arpit.bagri asked Aug 6, 2023
1,184 views
Why is the output of the below program 36? int main(){ int a = 1; int b = ++a * ++a * ++a; printf("%d", b ); ​​​​ return 0; }
1.4k
views
2 answers
6 votes
saurabh0709 asked Aug 1, 2023
1,399 views
What will be the output of the following code? _______ #include <stdio.h> int main(){ char val=250; int ans; ans= val+ !val + ~val + ++val; printf("%d", ans); return 0; }
1.1k
views
0 answers
0 votes
Abhijit Sen 4 asked May 7, 2018
1,095 views
Can someone explain why this is happening. I have found post increment has higher precedence than pre-increment . And Post increment is left ... has differenet value.https://www.geeksforgeeks.org/c-operator-precedence-associativity/
558
views
1 answers
1 votes
Kalpataru Bose asked Jul 27, 2018
558 views
Let "if x then y else z" denote the expression and this expression can be represented ad "?xyz" using ternary prefix operatorthe prefix operator for the following expression is If a ... ac?+ab+acB) ?a?-cd+ac*ac+abC)?a-cd?+ac*ac+abD )none