Here you can find the source of intToBytes(int n)
Parameter | Description |
---|---|
n | the integer value to convert |
public static byte[] intToBytes(int n)
//package com.java2s; //License from project: Apache License public class Main { /**/*from w w w. j a va 2 s. c o m*/ * Convert a integer value to bytes * * @param n the integer value to convert * @return bytes of then integer value * @since 1.0 */ public static byte[] intToBytes(int n) { byte[] b = new byte[4]; for (int i = 0; i < 4; i++) { b[i] = (byte) (n >> (24 - i * 8)); } return b; } }