Here you can find the source of toInteger(final byte[] data)
Parameter | Description |
---|---|
data | 4-byte array to convert |
public static int toInteger(final byte[] data)
//package com.java2s; /*// ww w .j ava 2s . c o m * File: HashFunctionUtil.java * Authors: Kevin R. Dixon * Company: Sandia National Laboratories * Project: Cognitive Foundry * * Copyright Jan 26, 2011, Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the U.S. Government. * Export of this program may require a license from the United States * Government. See CopyrightHistory.txt for complete details. * */ public class Main { /** * Converts the 4-byte array to a Big Endian int. * @param data * 4-byte array to convert * @return * Big Endian int representation of the byte array */ public static int toInteger(final byte[] data) { if (data.length != 4) { throw new IllegalArgumentException("data must be of length 4"); } return toInteger(data, 0); } /** * Converts the 4 bytes in the given array starting at "offset" * to a Big Endian int. * @param data * Array to convert * @param offset * Offset into the array * @return * Big Endian int representation of the byte array at offset */ public static int toInteger(final byte[] data, final int offset) { return ((data[offset] & 0xff) << 24) | ((data[offset + 1] & 0xff) << 16) | ((data[offset + 2] & 0xff) << 8) | ((data[offset + 3] & 0xff)); } }