Java Integer to Byte Array intToBytes(int i)

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

Description

int To Bytes

License

Open Source License

Declaration

public static byte[] intToBytes(int i) 

Method Source Code

//package com.java2s;
/*/*  w  w w  .j a  v  a  2s .  com*/
 * @(#)ByteConvertUtil.java   V0.0.1 2015-2-3, ????1:37:07
 *
 * Copyright 2015 www.ifood517.com. All rights reserved.
 * www.ifood517.com PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

public class Main {

    public static byte[] intToBytes(int i) {
        byte[] intBytes = new byte[4];
        intBytes[0] = (byte) (i >> 24);
        intBytes[1] = (byte) (i >> 16);
        intBytes[2] = (byte) (i >> 8);
        intBytes[3] = (byte) (i >> 0);
        return intBytes;
    }

    public static byte[] intToBytes(int i, byte[] data, int index) {
        data[index] = (byte) (i >> 24);
        data[index + 1] = (byte) (i >> 16);
        data[index + 2] = (byte) (i >> 8);
        data[index + 3] = (byte) (i >> 0);
        return data;
    }
}

Related

  1. intToBytes(int i)
  2. intToBytes(int i)
  3. intToBytes(int i)
  4. intToBytes(int i)
  5. intToBytes(int i)
  6. intToBytes(int i)
  7. IntToBytes(int i)
  8. intToBytes(int i, byte[] data, int[] offset)
  9. intToBytes(int i_)