Java Integer to Byte Array int2bytes(int value)

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

Description

Converts Integer value to Array of bytes

License

Open Source License

Parameter

Parameter Description
value Integer to be transformed

Return

Array of bytes representing Integer value

Declaration

public static byte[] int2bytes(int value) 

Method Source Code

//package com.java2s;
/*//from   w  w w  .j  av a2s  .co  m
 * Copyright (c) 2014 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 Integer value to Array of bytes
     *
     * @param value Integer to be transformed
     * @return Array of bytes representing Integer value
     */
    public static byte[] int2bytes(int value) {
        return new byte[] { (byte) (value >>> 24), (byte) (value >>> 16), (byte) (value >>> 8), (byte) value };
    }
}

Related

  1. int2bytes(int num, int len)
  2. int2bytes(int v)
  3. int2bytes(int val, byte[] bytes, int offset, boolean bigEndian)
  4. int2bytes(int value)
  5. int2Bytes(int value)
  6. int2bytes(int value, byte[] bytes, int off)
  7. int2bytes(int... numbers)
  8. int2bytes2(int src, byte[] dest)
  9. int32ToArray(int data)