- public static void toHex2(int num,int a,int i){
- if(num==0){
- System.out.print("0");
- return;
- }
- char[] arr = {'0','1','2','4','5','6','7','8','9','A','B','C','D','E','F'};
- char[] arr2 = new char[8];
- int pos= 0;
- while(num!=0){
- int temp = num&i;
- arr2[pos++]=arr[temp];//毕老师的视频temp是和角标对上的但是我编辑的时候要temp-1角标才和数组对上,但是这样的话转二进制时就会角标越界。
- num = num>>>a;
- }
- for(int x=pos-1;x>=0;x--){
- System.out.print(arr2[x]);
- }
复制代码 |
|