Shawngbk / Leecode

Questions of Leecode
0 stars 0 forks source link

405. Convert a Number to Hexadecimal(不怎么会) #139

Open Shawngbk opened 7 years ago

Shawngbk commented 7 years ago

public class Solution { char[] map = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'}; public String toHex(int num) { if(num == 0) return "0"; String res = ""; while(num != 0) { res = map[(num & 15)] + res; num = (num >>> 4); } return res; } }