Android Little Endian Convert shortAsLittleEnd(short val)

Here you can find the source of shortAsLittleEnd(short val)

Description

Converts a short value to an array in little-endian format.

Declaration

public static byte[] shortAsLittleEnd(short val) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from w  w w.j ava  2s .  c  o  m*/
     * Converts a short value to an array in little-endian format.
     * \param val The value to be converted.
     * \returns A byte array with the value in little-endian format.
     **/
    public static byte[] shortAsLittleEnd(short val) {
        byte[] array = new byte[2];
        return shortAsLittleEnd(array, 0, val);
    }

    /**
     * Convert a short value into an array in little-endian format, copying the
     * result in the passed array at the point especified.
     * \param a The array where the converted value should be copied.
     * \param i The starting point, int the array \a a where the copy should
     * start.
     * \param v The value to be converted and copied.
     * \returns \a a.
     **/
    public static byte[] shortAsLittleEnd(byte[] a, int i, short v) {
        a[i + 1] = (byte) (0xFF & (v >> 8));
        a[i + 0] = (byte) (0xFF & v);
        return a;
    }
}

Related

  1. intAsLittleEnd(byte[] a, int i, int v)
  2. intAsLittleEnd(int val)
  3. longAsLittleEnd(byte[] a, int i, long v)
  4. longAsLittleEnd(long val)
  5. shortAsLittleEnd(byte[] a, int i, short v)
  6. uint32LittleEndian(int value)