Explanation:
Step 1: Understand the Bitwise NOT (~)
~5
- Bitwise NOT reverses all bits of a number.
- In Python, ~n is equivalent to -(n + 1).
Calculation:
\[
\sim 5 = -(5+1) = -6
\]
Step 2: Understand Bitwise AND (&)
~5 & 7
Substitute ~5 with -6:
-6 & 7
In binary (using two's complement representation):
-6 = ...11111010
7 = ...00000111
------------------
...00000010
Result:
\[
-6 \ \&\ 7 = 2
\]
Step 3: Understand Left Shift (<<)
3 << 2
- Left shift moves the binary bits two positions to the left.
- Each left shift by one position multiplies the number by 2.
Binary calculation:
3 = 0011
3 << 2 = 1100
Therefore:
\[
3 \times 2^2 = 12
\]
Step 4: Understand Bitwise XOR (^)
Now the original expression becomes:
2 ^ 12
Binary representation:
2 = 0010
12 = 1100
-----------
1110
XOR rules:
- Same bits produce 0.
- Different bits produce 1.
Therefore:
\[
2 \oplus 12 = 14
\]
3. Final Output
14
.png)
.png)


.png)

.png)

.png)

.png)

