简体   繁体   English

我不知道0xAA55进入字节数组(大小2)

[英]I dont know 0xAA55 get in byte array (size 2)

I developing TCP Server Program but I stucked this Server's Protocol the header is fixed by 0xAA55, header size is 2 Byte this is the problem I dont know fill in 0xAA55 to byte array 我正在开发TCP服务器程序,但我卡住了该服务器的协议,标题由0xAA55固定,标题大小为2字节,这是我不知道将0xAA55填充到字节数组的问题

byte[] tmp = new byte[2]; byte [] tmp =新的byte [2]; tmp = 0xAA55; tmp = 0xAA55;

this is not work.. 这是行不通的。

You could wrap tmp with a ByteBuffer and then use ByteBuffer.putShort(short) like 你可以换tmpByteBuffer ,然后用ByteBuffer.putShort(short)

byte[] tmp = new byte[2];
ByteBuffer bb = ByteBuffer.wrap(tmp);
bb.putShort((short) 0xAA55);
System.out.println(Arrays.toString(tmp));

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

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