如下内容:
十进制转十六进制的代码,为什么结果不对?
- public static void toHex(int num)
- {
- StringBuffer sb = new StringBuffer();
- while (num!=0)
- {
- int n1 = num&15;
- System.out.println(n1);
- if (n1>9)
- {
- sb.append((char)(n1-10+'a'));
- }
- else
- {
- sb.append(n1);
- }
- n1 = n1>>>4;
- }
- System.out.println(sb.reverse());
- }
复制代码
|
|