简体   繁体   English

将十六进制值转换为ascii

[英]Convert hexadecimal value to ascii

I have a java code that reads a memory file and display the hexadecimal value of the content. 我有一个Java代码,它读取一个内存文件并显示内容的十六进制值。 I want to convert that output to ASCII. 我想将该输出转换为ASCII。 Since i am new to java programming i need your valuable help. 由于我是Java编程的新手,因此需要您的宝贵帮助。 Please help me to do this. 请帮我做到这一点。 If you have any idea or any programs please send it to me. 如果您有任何想法或程序,请发送给我。 Thank you. 谢谢。

final FileInputStream fis = new FileInputStream("/path/to/file.dmp");

   final byte[] buf = new byte[512];
   int readSize = 0;
   while ((readSize = fis.read(buf)) > -1) {
for (int i = 0; i < readSize; i++) {
    final byte curByte = buf[i];
    System.out.print(String.format("%02X ", curByte));
}   
}fis.close();

You can split the hex string in groups of two and use the function Integer.parseInt(subString, 16); 您可以将十六进制字符串分成两部分,并使用Integer.parseInt(subString, 16);函数Integer.parseInt(subString, 16); to convert it to an integer. 将其转换为整数。 You can then cast it to a byte or char . 然后可以将其char转换为bytechar

you can use 您可以使用

 Integer.toString((int)b, 10); 

this how Byte class in java does 这是Java中的Byte类的工作方式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM