For python it seems to generate a more reasonable result at least:
# Swap the sixth bit and seventeenth bit of a 32-bit signed integer.
def swap_bits(x):
# Get the bit at position 6 and 17.
bit6 = x & (1 << 6)
bit17 = x & (1 << 17)
# Swap the bits.
x = x ^ (bit6 << 17)
x = x ^ (bit17 << 6)
return x