Java Integer to intToLittleEndian(int val)

Here you can find the source of intToLittleEndian(int val)

Description

Converts a long to a little-endian four-byte array

License

Open Source License

Parameter

Parameter Description
val a parameter

Return

array of byte representing little-endian encoding of the value

Declaration

public final static byte[] intToLittleEndian(int val) 

Method Source Code

//package com.java2s;
/*/*w  w  w  .  j a va 2s.c  o  m*/
 * Copyright (c) 2014 Stephan D. Cote' - All rights reserved.
 * 
 * This program and the accompanying materials are made available under the 
 * terms of the MIT License which accompanies this distribution, and is 
 * available at http://creativecommons.org/licenses/MIT/
 *
 * Contributors:
 *   Stephan D. Cote 
 *      - Initial API and implementation
 */

public class Main {
    /**
     * Converts a long to a little-endian four-byte array
     *
     * @param val
     *
     * @return array of byte representing little-endian encoding of the value
     */
    public final static byte[] intToLittleEndian(int val) {
        final byte[] b = new byte[4];

        for (int i = 0; i < 4; i++) {
            b[i] = (byte) (val % 256);
            val = val / 256;
        }

        return b;
    }
}

Related

  1. intToInteger(int[] array)
  2. intToIntegerArray(int[] array)
  3. intToLengthHexByte(int args, int hexLength)
  4. intToLetter(int index)
  5. intToLex(int v)
  6. intToLittleEndian(int value)
  7. intToMCInts(int i)
  8. intToMmss(int ns)
  9. intToNetworkByteOrder(int num, byte[] buf, int start, int count)