1
\$\begingroup\$

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).

Input Format

The first line of the input contains the list size T, which is followed by T lines, each line having an integer from the list.

Constraints

\1ドル≤T≤100\$

\0ドル≤integer<2^{32}\$

Output Format

Output one line per element from the list with the requested result.

Solution

for _ in range(int(raw_input())):
 N = int(raw_input())
 N = N & 0xffffffff # 32 bit representation
 print N ^ 0xffffffff

Hint: https://stackoverflow.com/a/16745422/4260745

asked Sep 24, 2015 at 7:46
\$\endgroup\$
1
  • 1
    \$\begingroup\$ This code works fine for me. Have it here on ideone too: ideone.com/zvLAXx \$\endgroup\$ Commented Sep 24, 2015 at 10:34

1 Answer 1

2
\$\begingroup\$

There's not much to review; that said, the input is guaranteed to be between zero and \2ドル^{32}\,ドル so there is no point to the N & 0xffffffff really. Also the print statement would be more upwards compatible with Python 3 if it was used like a function, i.e. print(...).

answered Sep 24, 2015 at 15:24
\$\endgroup\$
1
  • \$\begingroup\$ No! It doesn't work without converting it to 32bit. Please check once. \$\endgroup\$ Commented Sep 26, 2015 at 13:35

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.