本帖最后由 FCRandR 于 2015-10-17 17:11 编辑
- public static void toHex2(int num)
- {
- char[] chs = {'0','1','2','3',
- '4','5','6','7',
- '8','9','A','B',
- 'C','D','E','F'};
- char[] ret = new char[8];
- int pos = 0;
- while(num != 0)
- {
-
- int tem = num & 0xf;
- ret[pos++]=chs[tem];
- System.out.println(chs[tem]);
- num = num >>> 4;
- }
- for (int i=ret.length-1; i>=0; i--)
- {
- System.out.print(ret[i]+",");
- }<span style="line-height: 30.8px;">//while循环和for循环打印的数据不一样,如图。java基础视频中老师的结果是 , , , , , ,3,C 其中空地存储的代码是\u0000</span>
- }//这样的区别是因为不同系统对未初始化数组的翻译不一样吗?
复制代码 |
|