Method 5: Swap using bitwise XOR operator Dry Run in PYTHON

Method 5: Swap using bitwise XOR operator is an interactive PYTHON dry run visualizer from the Io programs section. Study the source code, then use the execution controls to follow each step, variable update, highlighted line, and console output.

This page provides a browser-based dry run with source-code highlighting, auto-scroll, voice narration controls, and execution output for learning the program step by step.

Method 5: Swap using bitwise XOR operator Program Code

# Method 5: Using bitwise XOR operator
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))

print(f"\nBefore swap: a = {a}, b = {b}")
print(f"Binary: a = {bin(a)}, b = {bin(b)}")

# Swapping using XOR bitwise operator
a = a ^ b
b = a ^ b
a = a ^ b

print(f"\nAfter swap: a = {a}, b = {b}")
print(f"Binary: a = {bin(a)}, b = {bin(b)}")

View the complete Io programs page.

Program Console Method 5: Swap using bitwise XOR operator Topic: PYTHON Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.