public static int invertBits (int n) {
        int pow2 = 1;
        int bit = 0;
            int invertedNum = 0;
            while ( n > 0) {
              bit = (n & 1);
              if ( bit == 0 )
            	  invertedNum += pow2;
              n = n >> 1;
              pow2 *= 2;
          }
          return invertedNum;
        }