Java Integer to intToLittleEndian(int value)

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

Description

Converts an int to the corresponding 4-byte little endian array.

License

Open Source License

Declaration

static byte[] intToLittleEndian(int value) 

Method Source Code

//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

public class Main {
    /** Converts an int to the corresponding 4-byte little endian array. */
    static byte[] intToLittleEndian(int value) {
        return integerToLittleEndian(new byte[4], 0, value, 4);
    }/*from www  . j  av a2  s. c  o m*/

    /** Writes an int to the buffer as a 4-byte little endian array starting at offset. */
    static byte[] intToLittleEndian(byte[] buf, int offset, int value) {
        return integerToLittleEndian(buf, offset, value, 4);
    }

    /** Converts a integral value to the corresponding little endian array. */
    private static byte[] integerToLittleEndian(byte[] buf, int offset, long value, int numBytes) {
        for (int i = 0; i < numBytes; i++) {
            buf[i + offset] = (byte) ((value & (0xffL << (i * 8))) >> (i * 8));
        }
        return buf;
    }
}

Related

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