Bitwise Operators in C Programming MCQ Questions and Answers

Q1) Which bitwise operator in C performs a bit-by-bit logical AND between two integers?
A) Bitwise OR (|)
B) Bitwise XOR (^)
C) Bitwise NOT (~)
D) Bitwise AND (&)
Answer: D) Bitwise AND (&)

Q2) What does the ~ operator do in C when applied to an unsigned integer?
A) Shifts bits left by one
B) Inverts every bit (ones’ complement)
C) Sets all bits to zero
D) Copies the value unchanged
Answer: B) Inverts every bit (ones’ complement)

Q3) In C, what is the result of 5 & 3? (Assume plain int, standard binary)
A) 7
B) 1
C) 2
D) 0
Answer: B) 1

Q4) Which operator yields 1 for each bit position where the corresponding bits of the operands differ?
A) &
B) |
C) ^
D) ~
Answer: C) ^

Q5) What is the decimal result of 6 | 3?
A) 7
B) 5
C) 1
D) 8
Answer: A) 7

Q6) Which statement about left shift << in C is correct?
A) x << n divides x by 2^n (floor) for unsigned types.
B) x << n rotates bits of x to the left.
C) x << n multiplies x by 2^n for unsigned types (unless overflow).
D) x << n sets the sign bit only.
Answer: C) x << n multiplies x by 2^n for unsigned types (unless overflow).

Q7) Consider unsigned int x = 1U << 31;. What does this expression do on a 32-bit unsigned int?
A) Sets the least significant bit to 1
B) Sets bit 31 (most significant) to 1
C) Undefined behavior because shifting by 31 is invalid
D) Clears all bits
Answer: B) Sets bit 31 (most significant) to 1

Q8) In C, what happens if you right-shift a signed negative integer using >>?
A) Always logical right shift (zeros filled at left)
B) Always arithmetic right shift (sign bit replicated) — guaranteed by the standard
C) Behavior implementation-defined (could be arithmetic or logical)
D) Compiler error
Answer: C) Behavior implementation-defined (could be arithmetic or logical)

Q9) What is the result of ~0 for a typical 32-bit unsigned int?
A) 0
B) 0xFFFFFFFF (all ones)
C) -1 (undefined)
D) 1
Answer: B) 0xFFFFFFFF (all ones)

Q10) Which operator precedence is correct among the following (from higher to lower)?
A) ^ > & > |
B) & > ^ > |
C) | > ^ > &
D) ^ > | > &
Answer: B) & > ^ > |

Q11) Given int x = 9; int y = x >> 1;, what is y on typical two’s-complement systems?
A) 9
B) 4
C) 5
D) Undefined
Answer: B) 4

Q12) Which C expression isolates the lowest-order (least significant) set bit of n (n > 0)?
A) n & (n – 1)
B) n | (n – 1)
C) n & -n
D) ~n
Answer: C) n & -n

Q13) For n = 12 (binary 1100), what is n & (n – 1)?
A) 12
B) 8
C) 4
D) 0
Answer: B) 8

Q14) Which expression clears (sets to 0) bit k of x (0-based indexing)?
A) x | (1 << k)
B) x & ~(1 << k)
C) x ^ (1 << k)
D) x + (1 << k)
Answer: B) x & ~(1 << k)

Q15) Which expression toggles (flips) bit k of x?
A) x ^ (1 << k)
B) x & (1 << k)
C) x | (1 << k)
D) x + (1 << k)
Answer: A) x ^ (1 << k)

Q16) What does x & 0 evaluate to for any integer x?
A) x
B) 0
C) -x
D) Undefined
Answer: B) 0

Q17) What is the result of x | ~x for any integer x (in two’s complement)?
A) x
B) ~x
C) All bits set (i.e., -1 for signed representations)
D) 0
Answer: C) All bits set (i.e., -1 for signed representations)

Q18) Which code snippet checks if n is a power of two (for positive n)?
A) (n & (n + 1)) == 0
B) (n & (n – 1)) == 0
C) (n | (n – 1)) == 0
D) (n ^ (n – 1)) == 0
Answer: B) (n & (n – 1)) == 0

Q19) What is the binary result of 4 ^ 6?
A) 010 (2)
B) 110 (6)
C) 0100 (4)
D) 0000 (0)
Answer: A) 010 (2)

Q20) Which of the following is true about bitwise XOR ^?
A) x ^ x = x
B) x ^ x = 0
C) x ^ 0 = 0
D) x ^ 0 = x and x ^ x = 0 are both true
Answer: D) x ^ 0 = x and x ^ x = 0 are both true

Q21) Which C expression tests whether the 5th bit (0-based) of x is set?
A) (x & (1 << 5)) != 0
B) (x | (1 << 5)) != 0
C) (x ^ (1 << 5)) != 0
D) (x >> 5) | 1
Answer: A) (x & (1 << 5)) != 0

Q22) What will the expression (unsigned int)1 << 32 do on a platform where unsigned int is 32 bits?
A) Shift produces zero
B) Undefined behavior (shift count equals width)
C) Equivalent to 1 (no change)
D) Sets bit 32 successfully
Answer: B) Undefined behavior (shift count equals width)

Q23) Which construct can be used to pack multiple boolean flags into a single integer?
A) Separate int variables for each flag
B) A char per flag
C) Bit masking using bitwise operators
D) Using floating-point values
Answer: C) Bit masking using bitwise operators

Q24) Evaluate this code: unsigned int a = 5u; unsigned int b = a << 2; What is b?
A) 5
B) 10
C) 20
D) 1
Answer: C) 20

Q25) Which property holds for bitwise AND & and OR |?
A) Both are non-commutative
B) Both are commutative (order doesn’t matter)
C) Only & is commutative
D) Only | is commutative
Answer: B) Both are commutative (order doesn’t matter)

Q26) Consider int a = 12; int b = ~a;. If a is 00001100 (8-bit shown), b becomes:
A) 00001100
B) 11110011 (ones’ complement of a)
C) 11111111
D) Zero
Answer: B) 11110011 (ones’ complement of a)

Q27) Which of the following yields the sign-extended right shift on two’s-complement systems when applied to signed negative values?
A) Logical right shift
B) Arithmetic right shift
C) Left shift
D) Bitwise NOT
Answer: B) Arithmetic right shift

Q28) For unsigned int x = 0xF0F0; x >> 4; what happens?
A) Upper nibble becomes zeroed and lower bits shift right by 4
B) Bits rotate right by 4
C) Undefined behavior because x is hex
D) All bits become 1
Answer: A) Upper nibble becomes zeroed and lower bits shift right by 4

Q29) Which binary operation can be used to test whether two integers have opposite signs?
A) x & y
B) x ^ y checked for x ^ y < 0 (on signed)
C) x | y
D) ~(x ^ y)
Answer: B) x ^ y checked for x ^ y < 0 (on signed)

Q30) What is the purpose of (x & ~(1 << k)) | ((v & 1) << k) where v is 0 or 1?
A) Toggle bit k of x regardless of v
B) Set bit k of x to value v (0 or 1)
C) Count bits in x
D) Clear all bits except k
Answer: B) Set bit k of x to value v (0 or 1)

Q31) Which of these is true about bitwise operations on char when char is signed?
A) Always safe and identical to unsigned char results
B) May promote to int due to integer promotion before operation
C) They are performed on bytes without promotion
D) They cause compile-time errors
Answer: B) May promote to int due to integer promotion before operation

Q32) Given unsigned x = 0x0F; unsigned y = x << 4;, what is y in hex?
A) 0xF0
B) 0x0F
C) 0x00
D) 0xFF
Answer: A) 0xF0

Q33) What does the expression x &= ~(1 << k) do?
A) Sets bit k of x
B) Clears bit k of x
C) Toggles bit k of x
D) Leaves x unchanged
Answer: B) Clears bit k of x

Q34) In C, which operator has higher precedence: bitwise AND & or equality ==?
A) == has higher precedence
B) & has higher precedence
C) They have equal precedence
D) Precedence is undefined
Answer: A) == has higher precedence

Q35) What is (7 >> 1) & 3 evaluated as? (All decimal)
A) 3
B) 1
C) 0
D) 2
Answer: A) 3

Q36) Which bitwise expression yields the integer with all lower n bits set to 1 (assuming 0 <= n < width)?
A) (1 << n) – 1
B) ~((1 << n) – 1)
C) (1 << (n – 1))
D) (1 >> n)
Answer: A) (1 << n) – 1

Q37) For unsigned int x = 9;, what does (x >> 1) | (x << (32 – 1)) attempt to do?
A) Logical right shift only
B) Left shift only
C) A rotate-right by 1 (assuming 32-bit and defined behavior)
D) Clear all bits
Answer: C) A rotate-right by 1 (assuming 32-bit and defined behavior)

Q38) Why is rotation not provided as a built-in C operator?
A) It is impossible to implement in C
B) Because rotations depend on word width and are achieved using shifts and ORs
C) C does provide a rotate operator
D) Rotations are illegal in C standard
Answer: B) Because rotations depend on word width and are achieved using shifts and ORs

Q39) What is the result of this code snippet?
unsigned int x = 0xAA; // 10101010
unsigned int y = x ^ 0xFF;
A) y = 0x00
B) y = 0x55
C) y = 0xAA
D) y = 0xFF
Answer: B) y = 0x55

Q40) Which expression computes the bitwise complement of x?
A) ~x
B) !x
C) -x
D) x ^ 0
Answer: A) ~x

Q41) In C, the expression -x for an unsigned x results in:
A) The negative value in signed sense (undefined for unsigned)
B) (~x) + 1 modulo wrapping of unsigned arithmetic
C) A compile-time error
D) Always zero
Answer: B) (~x) + 1 modulo wrapping of unsigned arithmetic

Q42) If x is an unsigned char with value 0b00001111, what does x << 4 produce after integer promotions?
A) 0b11110000 as unsigned char directly
B) Promotions to int first then the shift, result depends on int width
C) Undefined behavior always
D) No effect
Answer: B) Promotions to int first then the shift, result depends on int width

Q43) Which of the following can be used to clear all bits except the lowest m bits?
A) x & ~((1u << m) – 1)
B) x | ((1u << m) – 1)
C) x & ((1u << m) – 1)
D) x ^ ((1u << m) – 1)
Answer: C) x & ((1u << m) – 1)

Q44) Evaluate: int x = -1; x >> 1; On a typical two’s-complement arithmetic-right-shift implementation, the result is:
A) Zero
B) -1 (still all ones)
C) A large positive number
D) Undefined always
Answer: B) -1 (still all ones)

Q45) Which expression is a fast way to divide a positive integer x by 8?
A) x >> 3
B) x << 3
C) x / 8 (not bitwise)
D) x ^ 8
Answer: A) x >> 3

Q46) What is a common use of x & (x – 1) in bit manipulation?
A) Count the number of set bits in x iteratively by clearing the lowest set bit each time
B) Swap bits between numbers
C) Reverse bits in x
D) Convert x to negative
Answer: A) Count the number of set bits in x iteratively by clearing the lowest set bit each time

Q47) For signed integer a, what does checking (a & (1 << (sizeof(a)*8 – 1))) determine?
A) If a is even
B) If a is odd
C) If the sign bit of a is set (negative in two’s complement)
D) If a is zero
Answer: C) If the sign bit of a is set (negative in two’s complement)

Q48) Which statement about shifting negative signed values is safest?
A) Always shift signed values without casting
B) Convert to unsigned before shifting to avoid implementation-defined behavior for right shifts
C) Right shift negative signed is always logical
D) Left shift of negative signed is always safe and defined
Answer: B) Convert to unsigned before shifting to avoid implementation-defined behavior for right shifts

Q49) What does x |= 1 << k; do?
A) Clears bit k in x
B) Sets bit k in x
C) Toggles bit k in x
D) Reverses x bits
Answer: B) Sets bit k in x

Q50) Which operation can be used to swap two integers a and b without a temporary variable using bitwise ops?
A) a = a ^ b; b = a ^ b; a = a ^ b;
B) a = a & b; b = a & b; a = a & b;
C) a = a | b; b = a | b; a = a | b;
D) a = a + b; b = a – b; a = a – b;
Answer: A) a = a ^ b; b = a ^ b; a = a ^ b;

Q51) Which of these statements is correct about operator ^= in C?
A) It’s a bitwise XOR assignment (x ^= y is x = x ^ y)
B) It is an exponentiation assignment operator
C) It does pointer arithmetic
D) It is illegal in C
Answer: A) It’s a bitwise XOR assignment (x ^= y is x = x ^ y)

Q52) Consider unsigned int x = 1; x <<= 31;. On a 32-bit unsigned int, what is the typical value of x?
A) 0
B) 1
C) 0x80000000
D) Undefined
Answer: C) 0x80000000

Q53) Which of the following yields true if exactly one of two boolean-like integers a and b is non-zero?
A) a & b
B) a | b
C) a ^ b (non-zero result)
D) ~(a ^ b)
Answer: C) a ^ b (non-zero result)

Q54) What does ~(x | y) equal by De Morgan’s laws (bitwise)?
A) ~x & ~y
B) ~x | ~y
C) x & y
D) x | y
Answer: A) ~x & ~y

Q55) Which of these expresses clearing the most significant bit (MSB) of a 32-bit unsigned int x?
A) x & 0x7FFFFFFF
B) x | 0x80000000
C) x ^ 0x80000000
D) x & 0xFFFFFFFF
Answer: A) x & 0x7FFFFFFF

Q56) Which expression computes the number with only the highest set bit of n retained? (e.g., n=13 (1101) -> result=8 (1000))
A) n & (n – 1)
B) n | (n >> 1) repeated then masked — common idiom: set all bits right of MSB then (n+1)>>1
C) n ^ (n – 1)
D) ~n
Answer: B) n | (n >> 1) repeated then masked — common idiom: set all bits right of MSB then (n+1)>>1

Q57) What is a safe way to perform a circular rotate right of 8-bit x by n bits (0 <= n < 8)?
A) (x >> n) | (x << n)
B) (x >> n) | (x << (8 – n))
C) (x << n) & (x >> (8 – n))
D) x >> (n & 7)
Answer: B) (x >> n) | (x << (8 – n))

Q58) Which is true about x ^ y ^ y?
A) Equals x ^ (y ^ y) which simplifies to x ^ 0 hence x
B) Equals 0 always
C) Equals y
D) Undefined
Answer: A) Equals x ^ (y ^ y) which simplifies to x ^ 0 hence x

Q59) Evaluate: int x = 3; int y = (x << 31) >> 31; On a system with arithmetic right shift, what is y?
A) 0
B) 1
C) -1
D) Undefined always
Answer: C) -1
(Note: x << 31 likely sets sign; arithmetic right shift replicates sign — but left shifting may overflow signed range; this is illustrative about sign propagation and implementation-defined aspects.)

Q60) Which bitwise trick checks if x is odd?
A) (x & 1) == 1
B) (x | 1) == 1
C) (x ^ 1) == 0
D) (x >> 1) == 1
Answer: A) (x & 1) == 1

Q61) For unsigned x = 0x12345678; unsigned y = (x >> 8) & 0xFF; what is y in hex?
A) 0x12
B) 0x34
C) 0x56
D) 0x78
Answer: C) 0x56

Q62) Which of the following is true regarding bitwise operations and endianness?
A) Bitwise operations are affected by endianness at the bit level
B) Bitwise operations operate on the integer value, independent of byte order for arithmetic/logic purposes
C) Endianness changes how & works
D) Endianness forbids << and >> usage
Answer: B) Bitwise operations operate on the integer value, independent of byte order for arithmetic/logic purposes

Q63) What will the expression (1u << k) produce when k is equal to the number of bits in unsigned?
A) Zero
B) Undefined behavior (shift count >= width)
C) 1
D) Highest bit set
Answer: B) Undefined behavior (shift count >= width)

Q64) Which standard C operator combines bitwise shift and assignment?
A) <<
B) >>
C) <<= and >>=
D) ->
Answer: C) <<= and >>=

Q65) For int x = 0; x = (x – 1) & 1; what useful effect does (x – 1) & 1 have if x is used as a boolean flag?
A) Always sets x to 0
B) Toggles x between 0 and 1 (with modular arithmetic)
C) Resets x to 1 only
D) Causes undefined behavior
Answer: B) Toggles x between 0 and 1 (with modular arithmetic)

Q66) What does (~x) & mask do?
A) Sets the bits of x specified by mask to 1
B) Clears the bits of x specified by mask
C) Inverts bits of x then clears all bits outside mask — complement within mask
D) Rotates bits
Answer: C) Inverts bits of x then clears all bits outside mask — complement within mask

Q67) Which of the following is true about x & (~0) in C?
A) Always zero
B) Equivalent to x (since ~0 has all bits 1)
C) Undefined behavior
D) Equivalent to ~x
Answer: B) Equivalent to x (since ~0 has all bits 1)

Q68) Which operation would you use to pack two 16-bit unsigned values a and b into a 32-bit u as u = (a << 16) | b;? What must you ensure about a?
A) That a fits in 16 bits (no overflow)
B) That a is negative
C) That a is a pointer
D) Nothing — any a is fine
Answer: A) That a fits in 16 bits (no overflow)

Q69) Evaluate: 0xFF & ~0x0F in hex.
A) 0xFF
B) 0xF0
C) 0x0F
D) 0x00
Answer: B) 0xF0

Q70) Which expression yields the parity (even/odd number of 1-bits) of a 32-bit integer x using XOR?
A) x & (x – 1)
B) x ^ (x >> 1) ^ (x >> 2) … repeated folding pattern ending in &1
C) ~x
D) x | (x – 1)
Answer: B) x ^ (x >> 1) ^ (x >> 2) … repeated folding pattern ending in &1

Q71) For the expression (~(1 << k)), what does it represent?
A) A mask with all bits zero except bit k set to 1
B) A mask with bit k cleared and all other bits set to 1
C) Always zero
D) Always one
Answer: B) A mask with bit k cleared and all other bits set to 1

Q72) Which of the following is a correct way to set the 3 least significant bits of x to 1?
A) x |= 7;
B) x &= 7;
C) x ^= 7;
D) x = x << 3;
Answer: A) x |= 7;

Q73) What is the effect of x ^ 0xFFFFFFFF on a 32-bit x?
A) Leaves x unchanged
B) Inverts all bits of x
C) Sets x to zero
D) Sets x to all ones
Answer: B) Inverts all bits of x

Q74) Which operation is most appropriate to merge two bitfields high and low into a single integer where low occupies the lower n bits?
A) high | low
B) (high << n) | (low & ((1u<<n)-1))
C) high & low
D) low << high
Answer: B) (high << n) | (low & ((1u<<n)-1))

Q75) Which expression will yield the original value x after the sequence x ^= y; y ^= x; x ^= y;?
A) No change — the swap fails
B) Variables are swapped; original x is now in y and vice versa
C) x will be zero
D) Undefined behavior always
Answer: B) Variables are swapped; original x is now in y and vice versa

Q76) What is the result of (int)(unsigned) -1 in typical implementations where int is 32-bit signed and unsigned is 32-bit?
A) -1
B) 0xFFFFFFFF interpreted as signed -> -1
C) Implementation-defined but usually -1
D) Always zero
Answer: B) 0xFFFFFFFF interpreted as signed -> -1

Q77) Which of the following is true about left shifting a negative signed integer?
A) Always defined and safe
B) Undefined behavior if it causes overflow or shifting into sign bit for signed types
C) Equivalent to right shift
D) Converts to unsigned then shifts
Answer: B) Undefined behavior if it causes overflow or shifting into sign bit for signed types

Q78) What does (x & -x) return for x = 18 (binary 10010)?
A) 2 (10 binary)
B) 16 (10000 binary)
C) 18
D) 0
Answer: A) 2 (10 binary)

Q79) Which of the following is a correct idiom to test if nth bit of x is zero?
A) (x & (1 << n)) != 0
B) (x & (1 << n)) == 0
C) (x | (1 << n)) == 0
D) (x ^ (1 << n)) > 0
Answer: B) (x & (1 << n)) == 0

Q80) When combining masks, what does (mask1 & mask2) represent?
A) Bits set in either mask1 or mask2
B) Bits set in both mask1 and mask2 (intersection)
C) Bits set in mask1 but not mask2
D) Bits that are toggled between two masks
Answer: B) Bits set in both mask1 and mask2 (intersection)

Q81) What will happen if you evaluate 1 << -1 in C?
A) Shifts left by -1 (right shift)
B) Undefined behavior (negative shift count)
C) Equivalent to 1 << 1
D) Produces zero
Answer: B) Undefined behavior (negative shift count)

Q82) Which is the best explanation for (~0U >> 1) for unsigned type?
A) Produces zero
B) Produces all ones shifted right by 1 producing leading zeros — result has high bit 0 and others 1
C) Undefined behavior
D) Produces negative one
Answer: B) Produces all ones shifted right by 1 producing leading zeros — result has high bit 0 and others 1

Q83) What is the primary difference between & (bitwise AND) and && (logical AND) in C?
A) & performs boolean-short-circuit; && performs bitwise
B) & is bitwise and works on integer bits; && is logical and yields 1 or 0 after boolean evaluation and short-circuits
C) No difference; they are interchangeable
D) && is deprecated
Answer: B) & is bitwise and works on integer bits; && is logical and yields 1 or 0 after boolean evaluation and short-circuits

Q84) What does ~(x & y) equal by De Morgan’s laws (bitwise)?
A) ~x & ~y
B) ~x | ~y
C) x | y
D) x & y
Answer: B) ~x | ~y

Q85) Which correct statement about integer promotion and bitwise operators is true?
A) Operands smaller than int are promoted to int (or unsigned int) before applying bitwise ops
B) No promotion occurs; char remains char
C) They are converted to float first
D) Bitwise operators only work on long
Answer: A) Operands smaller than int are promoted to int (or unsigned int) before applying bitwise ops

Q86) Given unsigned int x = 1u << 31; x >>= 31;, what will x be (assuming 32-bit unsigned)?
A) 0
B) 1
C) 0x80000000
D) Undefined
Answer: B) 1

Q87) For two integers a and b, which expression yields a mask with 1s where a and b have differing bits?
A) a & b
B) a | b
C) a ^ b
D) ~(a ^ b)
Answer: C) a ^ b

Q88) What is a danger of using bit shifts to multiply signed integers by powers of two?
A) There is no danger; always safe
B) Left shift may overflow signed range — undefined behavior
C) It is slower than multiplication
D) It always yields negative numbers
Answer: B) Left shift may overflow signed range — undefined behavior

Q89) Which of the following is correct to clear lower 16 bits of a 32-bit unsigned integer x?
A) x &= 0x0000FFFF
B) x &= 0xFFFF0000
C) x |= 0x0000FFFF
D) x ^= 0x0000FFFF
Answer: B) x &= 0xFFFF0000

Q90) What is the result of this snippet:
unsigned a = 0x1;
a <<= 31;
a <<= 1;
Assume 32-bit unsigned.
A) 0x00000002
B) 0x00000000 (wrap to zero) — shifting out all bits
C) 0x80000000
D) Undefined
Answer: B) 0x00000000 (wrap to zero) — shifting out all bits

Q91) How can you quickly check if an integer x is a power of two using bitwise ops and without loops?
A) (x & (x – 1)) == 0 && x != 0
B) (x & (x + 1)) == 0
C) (x ^ x – 1) == 0
D) x & -x
Answer: A) (x & (x – 1)) == 0 && x != 0

Q92) Which of these yields the same result as (~x) + 1 (for integers)?
A) -x (two’s complement arithmetic)
B) !x
C) x ^ -1
D) x & -x
Answer: A) -x (two’s complement arithmetic)

Q93) What is the result of (15 >> 1) ^ (15 >> 2)? (All decimal)
A) 4
B) 5
C) 7
D) 3
Answer: A) 4

Q94) Given unsigned x = 0xF0; unsigned y = (x & 0xF0) >> 4;, what is y in hex?
A) 0x0F
B) 0xF0
C) 0x0
D) 0xFF
Answer: A) 0x0F

Q95) Which of the following is true for x ^ (1 << k) if bit k was 0 before?
A) bit k becomes 0
B) bit k becomes 1 (it toggles)
C) all bits inverted
D) nothing changes
Answer: B) bit k becomes 1 (it toggles)

Q96) What does (x >> (n & 31)) ensure when n might be large on a 32-bit machine?
A) Prevents undefined shift by masking shift count to 0..31 range
B) It rotates bits
C) It doubles x
D) Has no effect
Answer: A) Prevents undefined shift by masking shift count to 0..31 range

Q97) For the code int x = 5; x = x << 1;, what is x?
A) 2
B) 10
C) 6
D) Undefined
Answer: B) 10

Q98) Which expression tests whether the kth bit (0-based) is set and then clears it atomically in typical bit-manipulation idioms?
A) if (x & (1<<k)) x &= ~(1<<k);
B) x ^= (1<<k);
C) x |= (1<<k);
D) x = (x & (1<<k))
Answer: A) if (x & (1<<k)) x &= ~(1<<k);

Q99) What is the simplest expression to get a value of 1 if x is non-zero, else 0, using bitwise ops?
A) !!x (uses logical not twice — not bitwise)
B) (x != 0) (not bitwise)
C) ((x | -x) >> (sizeof(x)*8 – 1)) & 1 — bitwise trick
D) x & 1 (works only for odd/even)
Answer: C) ((x | -x) >> (sizeof(x)*8 – 1)) & 1 — bitwise trick

Q100) Which of the following best summarizes why bitwise operations are useful in systems programming?
A) They provide convenient floating point arithmetic
B) They allow compact representation of flags, fast arithmetic by powers of two, masking and bit-field manipulation, and hardware-level control
C) They are slower than any arithmetic alternative
D) They automatically make code portable without care for types
Answer: B) They allow compact representation of flags, fast arithmetic by powers of two, masking and bit-field manipulation, and hardware-level control