@@ -0,0 +1,1328 @@
+package com.fulin.Math;%0Aimport java.util.HashMap;%0A/**%0A * Created by fulin on 18-2-11.%0A */%0Apublic class ReverseBits %7B%0A%0A    public static void main(String%5B%5D args)%7B%0A        System.out.println(Long.toBinaryString(2147483647L));%0A//        System.out.println(reverseBits(2147483647L));%0A    %7D%0A%0A    public int reverseBits(int n) %7B%0A        int result = 0;%0A        for(int i=0;i%3C 32 ;i++ , n %3E%3E= 1)%7B%0A            result = result %3C%3C 1 %7C n & 1;%0A        %7D%0A        return result;%0A    %7D%0A%0A    private HashMap%3CByte ,Integer%3E cache = new HashMap%3CByte ,Integer%3E ();%0A    public int reverseBitsForMult(int n) %7B%0A        byte%5B%5D bytes = new byte%5B4%5D;%0A        for (int i = 0; i %3C 4; i++) // convert int into 4 bytes%0A            bytes%5Bi%5D = (byte)((n %3E%3E%3E 8*i) & 0xFF);%0A        int result = 0;%0A        for (int i = 0; i %3C 4; i++) %7B%0A            result += reverseByte(bytes%5Bi%5D); // reverse per byte%0A            if (i %3C 3)%0A                result %3C%3C= 8;%0A        %7D%0A        return result;%0A    %7D%0A%0A    private Integer reverseByte(Byte b)%7B%0A        Integer result = cache.get(b);%0A        if(result != null)%7B%0A            return result;%0A        %7D%0A        result = 0;%0A        for (int i = 0; i %3C 8; i++) %7B%0A            result += ((b %3E%3E%3E i) & 1);%0A            if (i %3C 7)%0A                result %3C%3C= 1;%0A        %7D%0A        cache.put(b, result);%0A%0A        return result;%0A%0A    %7D%0A%7D%0A

leetcode :190. Reverse Bits