publicclassTest{publicstaticvoidmain(String[] args){Solution solution =newSolution();System.out.println(Integer.toBinaryString(solution.reverseBits(-3)));}}classSolution{publicintreverseBits(int n){char[] chars =Integer.toBinaryString(n).toCharArray();int len = chars.length;int sign = chars[len -1]=='0'?0:Integer.MIN_VALUE;int sum =0;for(int i = len -2; i >=0; i--){if(chars[i]=='1'){
sum +=Math.pow(2,31-(len - i -1));}}return sign | sum;}}classSolution1{publicintreverseBits(int n){returnInteger.reverse(n);}}