Java Integer to Byte Array intToByteArray4(int i)

Here you can find the source of intToByteArray4(int i)

Description

Converts an integer number into a 4 bytes array

License

Open Source License

Parameter

Parameter Description
i the integer number

Return

the byte array

Declaration

public static byte[] intToByteArray4(int i) 

Method Source Code

//package com.java2s;
/*//from ww w .j av a 2 s .  co m
 * Copyright (c) 2013, 2015 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */

public class Main {
    /**
     * Converts an integer number into a 4 bytes array
     *
     * @param i the integer number
     * @return the byte array
     */
    public static byte[] intToByteArray4(int i) {
        return new byte[] { (byte) ((i >> 24) & 0xff), (byte) ((i >> 16) & 0xff), (byte) ((i >> 8) & 0xff),
                (byte) (i & 0xff) };
    }
}

Related

  1. intToByteArray(int value, byte[] data, int offset)
  2. intToByteArray(int value, byte[] dest)
  3. intToByteArray(int value, int nrOfBytes)
  4. intToByteArray(int value, int numBytes)
  5. intToByteArray2(final int integer)
  6. intToByteArray4(int value)
  7. intToByteArrayBE(int data)
  8. intToByteArrayLE(int v)
  9. intToByteLittleEnding(int j)