Here you can find the source of intToBytes(int v, final byte[] arr)
Parameter | Description |
---|---|
v | the given int |
arr | a given array of 4 bytes that will be returned with the data |
public static byte[] intToBytes(int v, final byte[] arr)
//package com.java2s; /*/*from w w w . j a v a 2 s . c o m*/ * Copyright 2015-16, Yahoo! Inc. * Licensed under the terms of the Apache License 2.0. See LICENSE file at the project root for terms. */ public class Main { /** * Returns a Little-Endian byte array extracted from the given int. * @param v the given int * @param arr a given array of 4 bytes that will be returned with the data * @return a Little-Endian byte array extracted from the given int. */ public static byte[] intToBytes(int v, final byte[] arr) { for (int i = 0; i < 4; i++) { arr[i] = (byte) (v & 0XFF); v >>>= 8; } return arr; } }