Here you can find the source of toInt(byte[] buf, int off)
int
at the specified offset in the given byte array.
Parameter | Description |
---|---|
buf | the byte array containing the 4 bytes to be converted to an <code>int</code>. |
off | offset in the byte array |
int
value of the 4 bytes.
public static int toInt(byte[] buf, int off)
//package com.java2s; /*/*from w w w . j a va 2s .c o m*/ * Copyright 1999-2010 University of Chicago * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License is * distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. * * See the License for the specific language governing permissions and limitations under the License. */ public class Main { /** * Converts 4 bytes to an <code>int</code> at * the specified offset in the given byte array. * * @param buf the byte array containing the 4 bytes * to be converted to an <code>int</code>. * @param off offset in the byte array * @return the <code>int</code> value of the 4 bytes. */ public static int toInt(byte[] buf, int off) { int lg = (buf[off] & 0xff) << 24; lg |= (buf[off + 1] & 0xff) << 16; lg |= (buf[off + 2] & 0xff) << 8; lg |= (buf[off + 3] & 0xff); return lg; } }