Here you can find the source of intToBytes(int num, byte[] bytes, int startIndex)
Parameter | Description |
---|---|
num | the integer to be translated |
bytes | [] the byte array |
startIndex | starting to store in this index |
public static int intToBytes(int num, byte[] bytes, int startIndex)
//package com.java2s; //License from project: Open Source License public class Main { /**/* w w w. j av a 2 s . c o m*/ * translate int into bytes, stored in byte array starting from startIndex * * @param num * the integer to be translated * @param bytes * [] the byte array * @param startIndex * starting to store in this index * @ret the index of the cell after storing the number. */ public static int intToBytes(int num, byte[] bytes, int startIndex) { bytes[startIndex] = (byte) (num & 0xff); bytes[startIndex + 1] = (byte) ((num >> 8) & 0xff); bytes[startIndex + 2] = (byte) ((num >> 16) & 0xff); bytes[startIndex + 3] = (byte) ((num >> 24) & 0xff); return startIndex + 4; } }