📘 Day 23 – Bit Manipulation in Python (QA Interview Focus)

🔹 Why QA Engineers Should Know Bit Manipulation?

Bit manipulation is not a primary focus in QA interviews, but it shows strong problem-solving ability and is sometimes used in logic-based coding rounds.

🔹 Core Bitwise Operators

Operator Symbol Example (a=5, b=3) Result
AND&5 & 31
OR|5 | 37
XOR^5 ^ 36
NOT~~5-6
Left Shift<<5 << 110
Right Shift>>5 >> 12

🔹 QA-Relevant Use Cases

1️⃣ Check if a number is even or odd

n = 7
if n & 1:
    print("Odd")
else:
    print("Even")
  

2️⃣ Check if a number is a power of 2

def is_power_of_two(n):
    return n > 0 and (n & (n - 1)) == 0

print(is_power_of_two(16))  # True
print(is_power_of_two(18))  # False
  

3️⃣ Find the single unique element in a list

nums = [2, 3, 5, 3, 2]
res = 0
for num in nums:
    res ^= num
print(res)  # 5
  

4️⃣ Swap two numbers without using extra variable

a, b = 5, 7
a = a ^ b
b = a ^ b
a = a ^ b
print(a, b)  # 7, 5
  

🔹 Sample QA Interview Questions

🔹 Interview Tip for QA

Focus only on basic coding problems with bitwise operators: Odd/Even check, Power of 2 check, Unique element with XOR, and Swapping without temp. Deeper DSA-level bit manipulation is not required for QA interviews.