java中输出hex bytes
2007-06-03 20:44
225 查看
在java里输出bytes array乍一想好像不难,但是做起来还是小有点学问,没想到也有个printf的方法,挺好用的,不废话看代码:
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
byte[] buffer = new byte[]
{
(byte)0x00, (byte)0xFE, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
(byte)0x01, (byte)0xCC, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
(byte)0x02, (byte)0x25, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00
};
for (int i = 0; i < buffer.length; i ++) {
System.out.printf("0x%02X ", buffer[i]);
}
}
}
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
byte[] buffer = new byte[]
{
(byte)0x00, (byte)0xFE, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
(byte)0x01, (byte)0xCC, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
(byte)0x02, (byte)0x25, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00
};
for (int i = 0; i < buffer.length; i ++) {
System.out.printf("0x%02X ", buffer[i]);
}
}
}
相关文章推荐
- Java bytesToHexString 解析
- 【Java】输出目录结构
- JAVA高级视频_IO输入与输出 思考与练习 学习笔记
- Java面试题之为什么输出结果会是 good and gbc?
- JAVA输入/输出流程序例题(文件和目录、字节流、字符流)
- 输出二位数组位置的用法--java
- java入门教程-8.3Java面向字符的输出流
- 输出希腊字母的java代码
- Java学习笔记1:在控制台输出金字塔
- java把字符串输出到文件和读取文件
- 【URLDecoder】java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in es
- java 中string与bytes的转换总结
- javaweb-day06-2&3 (Servlet - Response - 输出随机图片、请求重定向、web工程的URL地址写法、getOutputStream和getWriter互斥)
- java入门程序100例学习笔记(006输出测试)
- Java格式化XML输出
- Caused by: java.lang.OutOfMemoryError: Failed to allocate a 29433932 byte allocation with 14683576 free bytes and 14MB
- 输出所有最长公用子序列的实现(Java)
- java 命令行窗口输出希腊字母表
- java学习记录——用*输出三角形
- Java输出数组的内容