simple java solution


  • 0
    2
    public class Solution {
        public String toHex(int num) {
            String s = new String();
            do {
                int hex = num & 0x0000000f;
                if (hex < 10) {
                    s = hex + s;
                }
                else {
                    s = Character.toString((char) (hex - 10 + 'a')) + s;
                }
                num >>>= 4;
            } while (num != 0);
            return s;
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.