Java Integer to Byte Array intToByteArray(int data)

Here you can find the source of intToByteArray(int data)

Description

Converts the given integer value to a byte type array in Little endian order.

License

Open Source License

Parameter

Parameter Description
data the short type value to convert.

Return

a byte array representing given short number.

Declaration

public static byte[] intToByteArray(int data) 

Method Source Code

//package com.java2s;
/*//  w ww  .ja  v  a2s . c  om
 * This file is part of SerialPundit.
 * 
 * Copyright (C) 2014-2016, Rishi Gupta. All rights reserved.
 *
 * The SerialPundit is DUAL LICENSED. It is made available under the terms of the GNU Affero 
 * General Public License (AGPL) v3.0 for non-commercial use and under the terms of a commercial 
 * license for commercial use of this software. 
 * 
 * The SerialPundit 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.
 */

public class Main {
    /**
     * <p>Converts the given integer value to a byte type array in Little endian order.</p>
     * 
     * @param data the short type value to convert.
     * @return a byte array representing given short number.
     */
    public static byte[] intToByteArray(int data) {
        byte[] result = new byte[4];
        result[0] = (byte) (data & 0xff);
        result[1] = (byte) ((data >>> 8) & 0xff);
        result[1] = (byte) ((data >>> 16) & 0xff);
        result[1] = (byte) ((data >>> 24) & 0xff);
        return result;
    }
}

Related

  1. intToByteArray(final int x)
  2. intToByteArray(final int x, final byte[] dst, final int offset)
  3. intToByteArray(int a)
  4. intToByteArray(int a)
  5. intToByteArray(int bytes)
  6. intToByteArray(int i)
  7. intToByteArray(int i)
  8. intToByteArray(int input)
  9. intToByteArray(int integer)