Here you can find the source of intToByteArray(int data)
Converts the given integer value to a byte type array in Little endian order.
Parameter | Description |
---|---|
data | the short type value to convert. |
public static byte[] intToByteArray(int data)
//package com.java2s; /*// w ww .ja v a2s . c om * This file is part of SerialPundit. * * Copyright (C) 2014-2016, Rishi Gupta. All rights reserved. * * The SerialPundit is DUAL LICENSED. It is made available under the terms of the GNU Affero * General Public License (AGPL) v3.0 for non-commercial use and under the terms of a commercial * license for commercial use of this software. * * The SerialPundit 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. */ public class Main { /** * <p>Converts the given integer value to a byte type array in Little endian order.</p> * * @param data the short type value to convert. * @return a byte array representing given short number. */ public static byte[] intToByteArray(int data) { byte[] result = new byte[4]; result[0] = (byte) (data & 0xff); result[1] = (byte) ((data >>> 8) & 0xff); result[1] = (byte) ((data >>> 16) & 0xff); result[1] = (byte) ((data >>> 24) & 0xff); return result; } }