Explanation:
1. int("11010", 2)
"11010" is a binary number.
The 2 tells Python to interpret it as base 2.
Binary 11010 = decimal 26.
int("11010", 2) # 26
2. int("10101", 2)
"10101" is also a binary number.
Python converts it from base 2 to decimal.
Binary 10101 = decimal 21.
int("10101", 2) # 21
3. ^ — Bitwise XOR
Now Python performs XOR:
11010
^ 10101
-------
01111
XOR rules:
Bit 1 Bit 2 Result
0 0 0
0 1 1
1 0 1
1 1 0
So:
11010
10101
-----
01111
01111 in binary = 15 in decimal.
4. print(...)
Finally, print() displays the result:
15
1. int("11010", 2)
-
"11010"is a binary number. -
The
2tells Python to interpret it as base 2. -
Binary
11010= decimal 26.
int("11010", 2) # 26
2. int("10101", 2)
-
"10101"is also a binary number. - Python converts it from base 2 to decimal.
-
Binary
10101= decimal 21.
int("10101", 2) # 21
3. ^ — Bitwise XOR
Now Python performs XOR:
11010^ 10101-------01111
XOR rules:
| Bit 1 | Bit 2 | Result |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
So:
1101010101-----01111
01111 in binary = 15 in decimal.
4. print(...)
Finally, print() displays the result:
15
✅ Final Output
15
15

0 Comments:
Post a Comment