Here you can find the source of bytesToInt(byte[] array, int offset)
Parameter | Description |
---|---|
array | The array to extract data from. |
offset | The offset in the array of the most significant byte. |
public static int bytesToInt(byte[] array, int offset)
//package com.java2s; /*//from w w w . j a v a 2 s . c om * Copyright 2013-2014 Colby Skeggs * * This file is part of the CCRE, the Common Chicken Runtime Engine. * * The CCRE is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * The CCRE 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 Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with the CCRE. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Extracts the big-endian integer starting at offset from array. This is * equivalent to: * <code>((array[offset] & 0xff) << 24) | ((array[offset+1] & 0xff) << 16) | ((array[offset+2] & 0xff) << 8) | (array[offset+3] & 0xff)</code> * * @param array The array * * * * * to extract data from. * @param offset The offset in the array of the most significant byte. * @return The integer extracted from the array. */ public static int bytesToInt(byte[] array, int offset) { int highWord = ((array[offset] & 0xff) << 24) | ((array[offset + 1] & 0xff) << 16); int lowWord = ((array[offset + 2] & 0xff) << 8) | (array[offset + 3] & 0xff); return highWord | lowWord; } }