Java Integer to Byte Array int32toByteArray(int i)

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

Description

intto Byte Array

License

Open Source License

Declaration

public static byte[] int32toByteArray(int i) 

Method Source Code

//package com.java2s;
/*//w  w  w .  jav  a2  s. c  o  m
 * Copyright (C) 2016 Miguel Rodriguez Perez <miguel@det.uvigo.gal>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    public static byte[] int32toByteArray(int i) {
        byte[] output = new byte[4];

        output[0] = (byte) ((i & 0xFF000000) >> 24);
        output[1] = (byte) ((i & 0x00FF0000) >> 16);
        output[2] = (byte) ((i & 0x0000FF00) >> 8);
        output[3] = (byte) (i & 0x000000FF);

        return output;
    }
}

Related

  1. int2bytes2(int src, byte[] dest)
  2. int32ToArray(int data)
  3. int32ToArrayInPlace(int data, byte[] buffer, int offset)
  4. int32ToByteArr(int val, byte[] arr, int offset)
  5. int32ToByteArray(int a)
  6. int32ToByteArray(int integer)
  7. int32ToByteArray(int value)
  8. integerToByteArray(final int integerToSerialize, final byte[] byteArray, final int offset)
  9. integerToByteArray(int a, byte[] buf)