Here you can find the source of toBytes(short sVal, byte[] bytes, boolean bigEndian)
public static void toBytes(short sVal, byte[] bytes, boolean bigEndian)
//package com.java2s; /*/*from w ww . ja va2s.c om*/ * Copyright 1999-2004 Carnegie Mellon University. * Portions Copyright 2002-2004 Sun Microsystems, Inc. * Portions Copyright 2002-2004 Mitsubishi Electric Research Laboratories. * All Rights Reserved. Use is subject to license terms. * * See the file "license.terms" for information on usage and * redistribution of this file, and for a DISCLAIMER OF ALL * WARRANTIES. * */ public class Main { /** Converts a short into a byte array. */ public static void toBytes(short sVal, byte[] bytes, boolean bigEndian) { if (bigEndian) { bytes[0] = (byte) (sVal >> 8); bytes[1] = (byte) (sVal & 0xff); } else { bytes[0] = (byte) (sVal & 0xff); bytes[1] = (byte) (sVal >> 8); } } }