void byteToHex(int num,char* buf) { const char array[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; int d1 = num / 16; int d2 = num % 16; sprintf(buf," 0x%c%c",array[d1],array[d2]); } void printByte(void* addr,int size){ char buf[size * 5]; for (int i = 0; i < size; i++) { byteToHex(((char*)addr)[i],buf+(i*5)); } ALOGE("%s",buf); }Java
public static String bytesToHexString(byte[] src) { StringBuilder stringBuilder = new StringBuilder(""); if (src == null || src.length <= 0) { return null; } for (int i = 0; i < src.length; i++) { int v = src[i] & 0xFF; stringBuilder.append("0x"); String hv = Integer.toHexString(v); if (hv.length() < 2) { stringBuilder.append(0); } stringBuilder.append(hv); if (i != src.length-1) { stringBuilder.append(","); } } return stringBuilder.toString(); }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)