您的位置:首页 > 编程语言 > Java开发

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]);

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: