字节数组转换.docVIP

  • 7
  • 0
  • 约6.4千字
  • 约 13页
  • 2018-01-01 发布于河南
  • 举报
字节数组转换

字节数组转换 /** * 通信格式转换 * * Java和一些windows编程语言如c、c++、delphi所写的网络程序进行通讯时,需要进行相应的转换 * 高、低字节之间的转换 * windows的字节序为低字节开头 * linux,unix的字节序为高字节开头 * java则无论平台变化,都是高字节开头 */ public class FormatTransfer { /** * 将int转为低字节在前,高字节在后的byte数组 * @param n int * @return byte[] */ public static byte[] toLH(int n) { byte[] b = new byte[4]; b[0] = (byte) (n 0xff); b[1] = (byte) (n 8 0xff); b[2] = (byte) (n 16 0xff); b[3] = (byte) (n 24 0xff); return b; } /** * 将int转为高字节在前,低字节在后的byte数组 * @param n int * @return byte[] */ public static byte[] toHH(int n) { byte[] b = new byte[4]; b[3] =

文档评论(0)

1亿VIP精品文档

相关文档