Here you can find the source of toBytes(int integer)
Parameter | Description |
---|---|
integer | a parameter |
public static final byte[] toBytes(int integer)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from w ww .j av a 2 s. c o m*/ * Convert integer to byte array<br/> * sample: 0x037fb4c7 => {03, 7f, b4, c7} * @param integer * @return */ public static final byte[] toBytes(int integer) { byte[] result = new byte[4]; result[0] = (byte) (integer >> 24); result[1] = (byte) (integer >> 16); result[2] = (byte) (integer >> 8); result[3] = (byte) (integer /* >> 0 */); return result; // return BigInteger.valueOf(integer).toByteArray(); } }