<filename>Problem Solving/Algorithms/Flipping bits.py
#!/bin/python3

import math
import os
import random
import re
import sys

#
# Complete the 'flippingBits' function below.
#
# The function is expected to return a LONG_INTEGER.
# The function accepts LONG_INTEGER n as parameter.
#

def flippingBits(n):
    # Write your code here
    print(f'bin(n): {bin(n)}')
    s = bin(n)[2:]
    t = s.maketrans("01", "10")
    s = s.translate(t)
    s = (32-len(s))*"1"+s
    return int(s, 2)

if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')

    q = int(input().strip())

    for q_itr in range(q):
        n = int(input().strip())

        result = flippingBits(n)

        fptr.write(str(result) + '\n')

    fptr.close()
