Here you can find the source of intToByteArray(int value)
Parameter | Description |
---|---|
value | Integer value to convert to byte array. |
public static byte[] intToByteArray(int value)
//package com.java2s; /**/* www . j a va 2s . co m*/ * Copyright (c) 2014-2016 Digi International Inc., * All rights not expressly granted are reserved. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. * * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343 * ======================================================================= */ public class Main { /** * Converts the given integer value into a byte array. * * @param value Integer value to convert to byte array. * * @return Byte array of the given integer (4 bytes length). * * @see #byteArrayToInt(byte[]) */ public static byte[] intToByteArray(int value) { return new byte[] { (byte) ((value >>> 24) & 0xFF), (byte) ((value >>> 16) & 0xFF), (byte) ((value >>> 8) & 0xFF), (byte) (value & 0xFF) }; } }