Java Byte Array to Int bytesToInteger(byte[] b)

Here you can find the source of bytesToInteger(byte[] b)

Description

Assemble four bytes to an int value, make sure that the passed bytes length is larger than 4.

License

Open Source License

Parameter

Parameter Description
bytes a parameter

Return

int value of bytes

Declaration

public final static int bytesToInteger(byte[] b) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2004 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from   ww w  .j a va2 s. com
 *  Actuate Corporation  - initial API and implementation
 *******************************************************************************/

public class Main {
    /**
     * Assemble four bytes to an int value, make sure that the passed bytes
     * length is larger than 4.
     * 
     * @param bytes
     * @return int value of bytes
     */
    public final static int bytesToInteger(byte[] b) {
        assert b.length >= 4;
        return ((b[0] & 0xFF) << 24) + ((b[1] & 0xFF) << 16) + ((b[2] & 0xFF) << 8) + ((b[3] & 0xFF) << 0);
    }
}

Related

  1. bytesToInt(final byte[] bytes, final int position, final int length, final int bitShiftStart, final int bitShitIncrement)
  2. bytesToInt(int off, byte... arr)
  3. bytesToInt16(byte highByte, byte lowByte)
  4. bytesToInt2(byte[] arr, int offset)
  5. bytesToIntArr(byte[] arr, int offset, int[] num, int soff, int size)
  6. bytesToInteger(byte[] b, int off)
  7. bytesToInteger(byte[] bytes)
  8. bytesToInts(byte[] a, int ao, int[] b, int bo, int len)
  9. bytesToInts(byte[] bytes, int shift, int[] spec)