Crack the Bits: Bitwise Algorithm Interview Quiz Quiz

  1. Q1

    Which bitwise operation can be used to check if a number is even?

    1. ANDing with 1
    2. ORing with 1
    3. XORing with 1
    4. NOTing with 1
  2. Q2

    What is the result of 10 XOR 15, assuming these are decimal numbers?

    1. 5
    2. 25
    3. 101015
    4. 9
  3. Q3

    Which bitwise operation can quickly multiply a number by 2?

    1. Left shift by 1
    2. Right shift by 1
    3. ANDing with 2
    4. ORing with 2
  4. Q4

    What is the time complexity of counting the set bits in an integer using a naive approach?

    1. O(log n)
    2. O(n)
    3. O(1)
    4. O(number of bits)
  5. Q5

    Which bitwise technique is commonly used to find the only non-repeating element in an array where all other elements appear twice?

    1. XOR
    2. AND
    3. OR
    4. NOT
  6. Q6

    Which bitwise operator can be used to clear a specific bit in a number?

    1. AND with a mask having 0 at that bit
    2. OR with a mask having 0 at that bit
    3. XOR with a mask having 0 at that bit
    4. NOT with a mask having 0 at that bit
  7. Q7

    Which of the following is the fastest method to determine if a number is a power of 2?

    1. n u0026 (n - 1) == 0
    2. n % 2 == 0
    3. n u003Eu003E 1 == 0
    4. n * 2 == 0
  8. Q8

    What does the expression `x u0026 -x` return?

    1. The lowest set bit of x
    2. The highest set bit of x
    3. All bits of x set to 0
    4. All bits of x set to 1
  9. Q9

    How can you toggle a specific bit in a number using bitwise operations?

    1. XOR with a mask having 1 at that bit
    2. AND with a mask having 1 at that bit
    3. OR with a mask having 1 at that bit
    4. NOT with a mask having 1 at that bit
  10. Q10

    What is the result of 5 u003Cu003C 2, assuming 5 is a decimal number?

    1. 10
    2. 20
    3. 52
    4. 25
  11. Q11

    Given two numbers, a and b, which bitwise operation can swap their values without using a temporary variable?

    1. XOR operations
    2. AND operations
    3. OR operations
    4. NOT operations
  12. Q12

    In the context of bitwise operations, what is a 'mask' commonly used for?

    1. Selecting specific bits
    2. Changing the data type
    3. Defining loop iterations
    4. Encrypting the data
  13. Q13

    What is the result of the expression 15 u003Eu003E 2, assuming 15 is a decimal number?

    1. 7
    2. 3
    3. 1
    4. 152
  14. Q14

    Which is an efficient algorithm to calculate the number of set bits in an integer?

    1. Brian Kernighan's Algorithm
    2. Dijkstra's Algorithm
    3. Bubble Sort Algorithm
    4. Merge Sort Algorithm
  15. Q15

    What is the purpose of the Ones' complement operator?

    1. Invert all the bits of a number
    2. Set all bits to 1
    3. Set all bits to 0
    4. No operation is performed