Java tutorial
//package com.java2s; public class Main { private static byte[] getLengthBytes(int packageLength) { if (packageLength > 65535) { throw new IllegalArgumentException("packageLength is too large"); } byte lByte = (byte) (packageLength & 0x00ff); byte hByte = (byte) ((packageLength & 0xff00) >> 0x08); return new byte[] { lByte, hByte }; } }