Bit Manipulation and C++ Concepts Quiz Quiz

  1. Bitwise AND Operation

    Which operator in C++ represents the bitwise AND operation?

    1. u0026
    2. u0026u0026
    3. |
    4. ^
    5. and
  2. Result of Bitwise XOR

    What is the result of 6 ^ 3 in C++?

    1. 5
    2. 9
    3. 3
    4. 7
    5. 2
  3. Left Shift Operator

    What will be the output of the following code snippet: int a = 2 u003Cu003C 3; What is the value of 'a'?

    1. 16
    2. 10
    3. 8
    4. 6
    5. 12
  4. Bitwise NOT Result

    If you apply the bitwise NOT operator '~' to 0 in C++, what result do you get?

    1. -1
    2. 0
    3. 1
    4. 255
    5. 4294967295
  5. Checking If Number Is Even

    Which code snippet correctly checks if an integer 'n' is even using bitwise operations in C++?

    1. if ((n u0026 1) == 0)
    2. if ((n | 1) == 1)
    3. if (n % 2)
    4. if ((n u0026u0026 1) == 1)
    5. if ((n ^ 1) == 1)
  6. Bitwise OR Usage

    Which C++ operator is used for the bitwise OR operation?

    1. |
    2. ||
    3. u0026
    4. or
    5. %%
  7. Clearing a Bit

    Given int x = 7, to clear the 1st bit from the right (least significant), which C++ statement achieves this?

    1. x = x u0026 ~1;
    2. x = x | 1;
    3. x = x ^ 0;
    4. x = x u0026u0026 1;
    5. x = x u003Eu003E 1;
  8. Swapping Two Values

    What is the correct bitwise way to swap integers 'a' and 'b' in C++ without using a third variable?

    1. a ^= b; b ^= a; a ^= b;
    2. a = b; b = a;
    3. a += b; b -= a; a -= b;
    4. swap(a, b);
    5. a = a | b; b = a u0026 b; a = a ^ b;
  9. Identifying Bit Shift Direction

    In C++, what does the 'u003Eu003E' operator do to the binary representation of a variable?

    1. Shifts bits right
    2. Shifts bits left
    3. Adds one
    4. Negates bits
    5. Flips every bit
  10. Counting Set Bits

    Which C++ code finds the number of 1's in the binary representation of integer n?

    1. while(n){ count+=(nu00261); nu003Eu003E=1; }
    2. while(n){ count+=(n|1); nu003Cu003C=1; }
    3. if(nu00261){count++;}
    4. count=n%2;
    5. count=nu0026n;