Here you can find the source of intToBytes(int i, byte[] backingStore, int offset)
Parameter | Description |
---|---|
i | A Java int value. |
public static byte[] intToBytes(int i, byte[] backingStore, int offset)
//package com.java2s; /*//from ww w . j a va2s . c om * Copyright (C) 2008 Pingtel Corp., certain elements licensed under a Contributor Agreement. * Contributors retain copyright to elements licensed under a Contributor Agreement. * Licensed to the User under the LGPL license. * */ import java.nio.ByteBuffer; public class Main { /** Number of bytes in a Java int. */ public static final int NUM_BYTES_IN_INT = 4; /** * Convert a Java int to a 4-byte array. * * @param i * A Java int value. * @return A 4-byte array representing the int value. */ public static byte[] intToBytes(int i, byte[] backingStore, int offset) { ByteBuffer byteBuffer = ByteBuffer.allocate(NUM_BYTES_IN_INT); byteBuffer.putInt(i); return byteBuffer.array(); } }