Here you can find the source of intTo2LengthBytes(int i)
public static byte[] intTo2LengthBytes(int i)
//package com.java2s; /*/*from w ww . ja v a 2 s . c o m*/ * @(#)ByteConvertUtil.java V0.0.1 2015-2-3, ????1:37:07 * * Copyright 2015 www.ifood517.com. All rights reserved. * www.ifood517.com PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ public class Main { public static byte[] intTo2LengthBytes(int i) { short s = (short) i; return shortToBytes(s); } public static byte[] intTo2LengthBytes(int i, byte[] data, int index) { short s = (short) i; return shortToBytes(s, data, index); } public static byte[] shortToBytes(short s) { byte[] shortBytes = new byte[2]; shortBytes[0] = (byte) (s >> 8); shortBytes[1] = (byte) (s >> 0); return shortBytes; } public static byte[] shortToBytes(short s, byte[] data, int index) { data[index] = (byte) (s >> 8); data[index + 1] = (byte) (s >> 0); return data; } }