Skills101
← All practice quizzes

Quiz: Bitwise Operators in C

5 questions · new set on every retakeNo time limitPass: 60%+10 XP on first pass

Work directly with the bits of an integer. Learn &, |, ^, ~, << and >>, the four bit-mask tricks (set, clear, toggle, check), classic interview programs and bit-fields inside structures.

Log in to take the quiz

Free account · see your score, answers and explanations, earn XP

  1. Question 1

    What does this print?

    #include <stdio.h>
    int main(void) {
        int a = 6, b = 3;
        printf("%d %d %d", a & b, a | b, a ^ b);
        return 0;
    }
    
  2. Question 2

    What is the value of ~7 on a two's complement machine?

  3. Question 3

    Which expression clears bit 3 of x?

  4. Question 4

    What does this print?

    #include <stdio.h>
    int main(void) {
        unsigned n = 29;
        int c = 0;
        while (n) { n &= n - 1; c++; }
        printf("%d", c);
        return 0;
    }
    
  5. Question 5

    Why does (n & (n - 1)) == 0 (with n > 0) mean n is a power of two?

🎯 Today’s placement challenge — 10 questions, no login. Can you score 10/10?Take today’s challenge →