Here you can find the source of intToByteArray(final int x, final byte[] dst, final int offset)
Parameter | Description |
---|---|
x | The integer |
dst | The byte array (length = 4) |
offset | The offset of the encoded integer in the byte array |
public static final void intToByteArray(final int x, final byte[] dst, final int offset)
//package com.java2s; /**//from w w w . j a va 2s.c o m * Copyright (c) 2014, Sindice Limited. All Rights Reserved. * * This file is part of the SIREn project. * * SIREn is a free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of * the License, or (at your option) any later version. * * SIREn is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public * License along with this program. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Convert an integer to a byte array. * * @param x The integer * @param dst The byte array (length = 4) * @param offset The offset of the encoded integer in the byte array */ public static final void intToByteArray(final int x, final byte[] dst, final int offset) { dst[offset + 3] = (byte) (x & 0x000000ff); dst[offset + 2] = (byte) ((x & 0x0000ff00) >>> 8); dst[offset + 1] = (byte) ((x & 0x00ff0000) >>> 16); dst[offset + 0] = (byte) ((x & 0xff000000) >>> 24); } }