## Performing Bitwise XOR in Python

#### Performing Bitwise XOR in Python

Problem: You want to perform a bitwise XOR operation in Python to manipu late binary data or check for differences between two binary numbers.
Solution:In Python, you can use the ^ operator to perform a bitwise XOR operation. Here's how you can do it:
##### Program
def my_function():
result = 7 ^ 3
print(result)

if __name__=="__main__":
my_function()
##### Output:

4

# XOR two binary numbers as integers
def my_function():
binary_result = int( '10101 ' , 2) ^ int( '11010 ' , 2)
print(binary_result) # binary_result will be 15

if __name__=="__main__":
my_function()

##### Output:

15

def my_function():
# XOR two binary numbers as strings
binary_strl = '10101'
binary_str2 = '11010'

# XOR operation using a loop for binary strings of the same length
result_str = ''. join( [ '1' if a != b else '0' for a, b in
zip(binary_strl, binary_str2)])
print(result_str)
if __name__=="__main__":
my_function()

##### Output:

01111

In this code:
This code demonstrates how to perform a bitwise XOR operation on integers and binary numbers, as well as how to manually XOR binary strings bit by bit. Bitwise XOR is a fundamental operation in working with binary data and can be used for various purposes in Python programming.