Java Integer to Byte Array intToByteArrayLE(int v)

Here you can find the source of intToByteArrayLE(int v)

Description

Convert an integer to byte array using Little Endian representation

License

Open Source License

Parameter

Parameter Description
v the integer

Return

the byte array representing the integer

Declaration

public static byte[] intToByteArrayLE(int v) 

Method Source Code

//package com.java2s;
/*//from  w w  w. j av a2  s .  c o m
 *  This file is part of Gjokii.
 *
 *  Gjokii is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Gjokii is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with Gjokii.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Convert an integer to byte array using Little Endian representation
     * 
     * @param v
     *            the integer
     * @return the byte array representing the integer
     */
    public static byte[] intToByteArrayLE(int v) {
        return new byte[] { (byte) ((v & 0x000000FF)), (byte) ((v & 0x0000FF00) >> 8),
                (byte) ((v & 0x00FF0000) >> 16), (byte) ((v & 0xFF000000) >> 24) };
    }
}

Related

  1. intToByteArray(int value, int numBytes)
  2. intToByteArray2(final int integer)
  3. intToByteArray4(int i)
  4. intToByteArray4(int value)
  5. intToByteArrayBE(int data)
  6. intToByteLittleEnding(int j)
  7. intToByteMSB(int in)
  8. intToBytes(byte[] arr, int offset, int num)
  9. intToBytes(byte[] bytes, int index, int value)