Bitwise Operators Basics Quiz Quiz

Assess your understanding of fundamental bitwise operators, including their meanings, effects on binary data, and common usage scenarios. Enhance your grasp of how bitwise AND, OR, XOR, NOT, and shift operations manipulate integer values at the bit level.

  1. Bitwise AND Evaluation

    What is the result in decimal form when applying the bitwise AND operator to the numbers 12 and 5?

    1. 4
    2. 7
    3. 17
    4. 8

    Explanation: The bitwise AND operator compares each bit of two numbers and returns a new number with bits set to 1 only if both bits are 1. For 12 (1100) and 5 (0101), only the third bit from the left is set in both, resulting in 0100, which equals 4. Option 8 comes from an OR operation, not AND. Option 17 is not related to these numbers, and 7 is the result of 12 XOR 5.

  2. Bitwise OR Operation

    Given the integers 9 and 6, what will 9 | 6 (bitwise OR) evaluate to?

    1. 1
    2. 15
    3. 0
    4. 12

    Explanation: The bitwise OR operator sets each bit to 1 if either operand is 1. The binary of 9 is 1001, and 6 is 0110; their bitwise OR is 1111, which equals 15 in decimal. Option 1 results from an AND operation, 0 is only possible if both numbers are zero, and 12 is not the correct outcome here.

  3. Bitwise XOR Characteristics

    Which statement correctly describes the result of applying the bitwise XOR operator to two identical integers, such as 7 and 7?

    1. The result is always 1
    2. The result is always the sum of both numbers
    3. The result is always -1
    4. The result is always 0

    Explanation: Bitwise XOR returns 1 only for differing bits, so when two identical numbers are XORed, all corresponding bits are equal, resulting in all zeros. The sum of the numbers is unrelated to XOR, so that distractor is incorrect. The result is not always 1 or -1; these are incorrect assumptions for XOR with identical numbers.

  4. Bitwise NOT Outcome

    When the bitwise NOT operator (~) is applied to the 8-bit binary number 00001100, what is the resulting binary?

    1. 11110011
    2. 00001100
    3. 00000011
    4. 00001101

    Explanation: The bitwise NOT flips every bit, so 00001100 becomes 11110011. The second option is incrementing by 1, not NOT. The third option is the original value. The last option only flips some bits, not all. Thus, only flipping each bit (NOT) yields 11110011.

  5. Left Shift Effect

    What is the result of left-shifting the binary value 0010 by 2 positions (using u003Cu003C 2)?

    1. 1000
    2. 0001
    3. 0110
    4. 0011

    Explanation: A left shift moves all bits to the left, inserting zeros from the right. Shifting 0010 (which is 2 in decimal) two positions left gives 1000 (8 in decimal). Option 0110 represents a different shift result, 0011 is a simple increment, and 0001 is incorrect for this shift.