Java Integer Create toInt(byte[] buf, int off)

Here you can find the source of toInt(byte[] buf, int off)

Description

Converts 4 bytes to an int at the specified offset in the given byte array.

License

Apache License

Parameter

Parameter Description
buf the byte array containing the 4 bytes to be converted to an <code>int</code>.
off offset in the byte array

Return

the int value of the 4 bytes.

Declaration

public static int toInt(byte[] buf, int off) 

Method Source Code

//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;
    }
}

Related

  1. toInt(byte[] b, int begin_index, int len)
  2. toInt(byte[] block, int pos, int len)
  3. toInt(byte[] bRefArr)
  4. toInt(byte[] buf)
  5. toInt(byte[] buf)
  6. toInt(byte[] buf, int pos)
  7. toInt(byte[] byteArray)
  8. toInt(byte[] bytes)
  9. toInt(byte[] bytes)