@@ -0,0 +1,1695 @@
+import org.junit.After;%0Aimport org.junit.Assert;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0A%0A/**%0A * Convert a number to hex%0A * %3Cp%3E%0A * Created by kiyan on 6/3/16.%0A */%0Apublic class ConvertToHex %7B%0A%0A    private ConvertToHex c;%0A%0A    /**%0A     *%0A     */%0A    public String convert(int num, int base) %7B%0A        // Deal with negative numbers%0A        boolean isNegative = false;%0A        if (num %3C 0 && base == 10) %7B%0A            isNegative = true;%0A            num = -num;%0A        %7D%0A%0A        // Process individual digits%0A        StringBuilder sb = new StringBuilder();%0A        while (num != 0) %7B%0A            int rem = num %25 base;%0A            char c = (char) ((rem %3E 9) ? (rem - 10) + 'a' : rem + '0');%0A            sb.insert(0, c);%0A            num = num / base;%0A        %7D%0A%0A        // If number is negative, append '-'%0A        if (isNegative)%0A            sb.insert(0, '-');%0A        return sb.toString();%0A    %7D%0A%0A    /**%0A     * Using bit mask and bit-wise operation%0A     */%0A    public String convertB(int num) %7B%0A        int mask = 15;%0A        StringBuffer sb = new StringBuffer();%0A        while (num != 0) %7B%0A            int index = (num & mask);%0A            char c = (char) ((index %3C 10) ? (index + '0') : ('a' + index - 10));%0A            sb.append(c);%0A            num = num %3E%3E%3E 4;%0A        %7D%0A        sb.reverse();%0A        return sb.toString();%0A    %7D%0A%0A    @Before%0A    public void setUp() %7B%0A        c = new ConvertToHex();%0A    %7D%0A%0A    @Test%0A    public void testPositiveNumbers() %7B%0A        String res = c.convert(80, 16);%0A        Assert.assertEquals(%2250%22, res);%0A        res = c.convert(3200, 16);%0A        Assert.assertEquals(%22c80%22, res);%0A    %7D%0A%0A    @After%0A    public void tearDown() %7B%0A        c = null;%0A    %7D%0A%7D%0A

add convert a number to heximal