62,614
社区成员
发帖
与我相关
我的任务
分享
public class Hex {
private static final char[] HEX = "0123456789abcdef".toCharArray();
private Hex() {
}
public static void main(String[] args) {
byte[] bytes = { 0 , 1 , 2 , (byte)0x7f };
System.out.println( toHex( bytes ) );
}
public static String toHex(byte[] bytes) {
if ( bytes == null ) {
return null;
}
char[] chs = new char[bytes.length << 1];
for ( int i = 0 , k = 0 ; i < bytes.length ; i++ ) {
chs[k++] = HEX[(bytes[i] & 0xf0) >>> 4];
chs[k++] = HEX[(bytes[i] & 0x0f)];
}
return new String(chs);
}
}