Android Utililty Methods Short to Byte Array Convert

List of utility methods to do Short to Byte Array Convert

Description

The list of methods to do Short to Byte Array Convert are organized into topic(s).

Method

byte[]shortToBytes(short number)
short To Bytes
int temp = number;
byte[] bytes = new byte[2];
for (int i = 0; i < bytes.length; i++) {
    bytes[i] = new Integer(temp & 0xff).byteValue();
    temp = temp >> 8;
return bytes;
byte[]shortToBytes(short number)
short To Bytes
int temp = number;
byte[] bytes = new byte[2];
for (int i = 0; i < bytes.length; i++) {
    bytes[i] = new Integer(temp & 0xff).byteValue();
    temp = temp >> 8;
return bytes;
byte[]short2ByteArray(short s)
short Byte Array
byte[] shortBuf = new byte[2];
for (int i = 0; i < 2; i++) {
    int offset = (shortBuf.length - 1 - i) * 8;
    shortBuf[i] = (byte) ((s >>> offset) & 0xff);
return shortBuf;
byte[]shortToByte(short number)
short To Byte
int temp = number;
byte[] b = new byte[2];
for (int i = (b.length - 1); i >= 0; i--) {
    b[i] = new Integer(temp & 0xff).byteValue();
    temp = temp >> 8;
return b;
byte[]shortToBytes(short i)
Returns a byte array containing the bytes of the given short in big endian order.
return new byte[] { (byte) (i >> 8), (byte) (i & 0xFF) };
byte[]shortToBytes(short number)
short To Bytes
int temp = number;
byte[] bytes = new byte[2];
for (int i = 0; i < bytes.length; i++) {
    bytes[i] = new Integer(temp & 0xff).byteValue();
    temp = temp >> 8;
return bytes;
byte[]shorts2bytesBE(short[] val)
shortsbytes BE
if (val == null)
    return null;
byte[] b = new byte[val.length << 1];
for (int i = 0; i < val.length; i++)
    ushort2bytesBE(val[i], b, i << 1);
return b;
byte[]shorts2bytesLE(short[] val)
shortsbytes LE
if (val == null)
    return null;
byte[] b = new byte[val.length << 1];
for (int i = 0; i < val.length; i++)
    ushort2bytesLE(val[i], b, i << 1);
return b;
byte[]getBytes(short data)
get Bytes
byte[] bytes = new byte[2];
bytes[0] = (byte) (data & 0xff);
bytes[1] = (byte) ((data & 0xff00) >> 8);
return bytes;
byte[]short2bytes(short val)
shortbytes
byte[] data = new byte[2];
data[0] = (byte) (val & 0xFF);
data[1] = (byte) (val >> 8 & 0xFF);
return data;