Code Review Stack Exchange is a question and answer site for peer programmer code reviews. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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: http://stackoverflow.com/a/16745422/4260745

share|improve this question
1  
This code works fine for me. Have it here on ideone too: ideone.com/zvLAXx – rolfl Sep 24 '15 at 10:34

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

share|improve this answer
    
No! It doesn't work without converting it to 32bit. Please check once. – CodeYogi Sep 26 '15 at 13:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.