I am trying to write an algorithm for the following problem.
Problem Statement.
You will be given a list of 32-bits unsigned integers. You are required to output the list of the unsigned integers you get by flipping bits in its binary representation (i.e. unset bits must be set, and set bits must be unset).
The code is as follows:
def bit_flip(a):
return ~a & 0xffffffff
t = raw_input("")
a = map(int, t.split())
map(lambda x: x ^ 0xffffffff, a)
for i in a:
print bit_flip(int(i))
The input is
3
2147483647
1
0
The output that i get is 4294967292
whereas the output is supposed to be
**2147483648
4294967294
4294967295**
I am not sure where I am wrong. The output is close to at least one line of the output, but not the same.
^and once inbit_flip) for each number.