标签:
import java.util.*;
public class Demo513
{
public static void main(String []args)
{
toHex_2(60);
}
public static void toHex_2(int num)
{
char []chs={‘0‘,‘1‘,‘2‘,‘3‘,
‘4‘,‘5‘,‘6‘,‘7‘,
‘8‘,‘9‘,‘A‘,‘B‘,
‘C‘,‘D‘,‘E‘,‘F‘};
char []arr=new char[8];
int pos=arr.length-1;
while(num!=0)
{
int temp=num&15;
arr[pos--]=chs[temp];
num=num>>>4;
}
System.out.println("pos="+pos);
for(int x=0;x<arr.length;x++)
{
System.out.print(arr[x]);
}
}
public static void toHex_1(int num)
{
for(int x=0;x<8;x++)
{
int temp=num&15;
if(temp>9)
System.out.print((char)(temp-10+‘A‘));
else
System.out.print(temp);
num=num>>>4;
}
}
public static void hex_2(int num)
{
char []chs={‘0‘,‘1‘,‘2‘,‘3‘,
‘4‘,‘5‘,‘6‘,‘7‘,
‘8‘,‘9‘,‘A‘,‘B‘,
‘C‘,‘D‘,‘E‘,‘F‘};
for(int x=0;x<8;x++)
{
int temp=num&15;
System.out.print(chs[temp]);
num=num>>>4;
}
}
}
标签:
原文地址:http://www.cnblogs.com/HJL085/p/5491649.html