private static byte[]theTestText ={0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,(byte) 0x88,(byte) 0x99,(byte) 0xAA,(byte) 0xBB,(byte) 0xCC,(byte) 0xDD,(byte) 0xEE,(byte) 0xFF};
String str= new String(theTestText); // converted the byte array to string
char ch = str.charAt(8); // extracting a specific character from string
我想从角色' ch'中获取十六进制值。如在原始字节数组中定义的那样,即0x88。有没有办法得到它?
答案 0 :(得分:0)
要获取字符串中的十六进制值:
String str= new String(theTestText); // converted the byte array to string
char ch = str.charAt(8); // extracting a specific character from string
String hex = String.format("%04x", (int) ch); // Converting the char to a string with its hexadecimal value