import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

// https://www.hackerrank.com/challenges/flipping-bits/problem
public class FlippingBits {

  private static String addLeadingZeros(String bits) {
    while (bits.length() < 32) {
      bits = "0" + bits;
    }
    return bits;
  }

  private static String toBits(long number) {
    String bits = Long.toBinaryString(number);
    return addLeadingZeros(bits);
  }

  private static String flipBits(String bits) {
    String flippedBits = "";
    for (char bit : bits.toCharArray()) {
      char flipped = (bit == '0') ? '1' : '0';
      flippedBits += flipped;
    }
    return flippedBits;
  }

  private static long toUnsignedNumber(String bits) {
    return Long.parseUnsignedLong(bits, 2);
  }

  public static void main(String[] args) throws IOException {
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
      int cases = Integer.parseInt(reader.readLine());
      for (int i = 0; i < cases; i++) {
        /*
         * Why do we use long instead of int? Because in Java there are signed integers only.
         * So if we get 2^31 + 1 as input, that value is greater than Integer.MAX_VALUE.
         */
        long inputCase = Long.parseLong(reader.readLine());
        String bits = toBits(inputCase);
        String flippedBits = flipBits(bits);
        long result = toUnsignedNumber(flippedBits);
        System.out.println(result);
      }
    }
  }
}

@@ -362,24 +362,546 @@
 g number) %7B%0A
+    StringBuilder builder = new StringBuilder();%0A    long remainder = number %25 2;%0A    long result = Math.floorDiv(number, 2);%0A    builder.append(remainder);%0A    while (result != 0) %7B%0A      remainder = result %25 2;%0A      result = Math.floorDiv(result, 2);%0A      builder.append(remainder);%0A    %7D%0A    String bits = builder.reverse().toString();%0A    return addLeadingZeros(bits);%0A  %7D%0A%0A//  /*%0A//   * Method to go from a number to an array of 32 bits using the Java API.%0A//   */%0A//  private static String toBits(long number) %7B%0A//
     String b
@@ -931,24 +931,26 @@
 ng(number);%0A
+//
     return a
@@ -967,24 +967,26 @@
 eros(bits);%0A
+//
   %7D%0A%0A  priva
@@ -1259,24 +1259,571 @@
 ing bits) %7B%0A
+    long unsignedNumber = 0;%0A    char%5B%5D chars = bits.toCharArray();%0A    for (int i = 0; i %3C chars.length; i++) %7B%0A      if (chars%5Bi%5D == '1') %7B%0A        /*%0A         * We use (chars.length - 1), because the conversion is zero-indexed.%0A         * 32 bits From 31 to 0.%0A         */%0A        unsignedNumber += Math.pow(2, chars.length - 1 - i);%0A      %7D%0A    %7D%0A    return unsignedNumber;%0A  %7D%0A%0A//  /*%0A//   * Method to go from an array of bits to an unsigned number%0A//   * using the Java API.%0A//   */%0A//  private static long toUnsignedNumber(String bits) %7B%0A//
     return L
@@ -1854,16 +1854,18 @@
 ts, 2);%0A
+//
   %7D%0A%0A  p

Comment methods that transform numbers to bits using the Java API and do it manually.