Returns the big-endian int value whose byte representation is the 4 bytes of bytes starting offset. - Java java.lang

Java examples for java.lang:int

Description

Returns the big-endian int value whose byte representation is the 4 bytes of bytes starting offset.

Demo Code

/*//from www.j  av  a 2  s. c o m
 * Copyright (c) 2011-2012 ICM Uniwersytet Warszawski All rights reserved.
 * See LICENCE file for licensing information.
 *
 * Derived from the code copyrighted and licensed as follows:
 * 
 * Copyright (c) Members of the EGEE Collaboration. 2004.
 * See http://www.eu-egee.org/partners/ for details on the copyright
 * holders.
 * 
 * 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.
 */
//package com.java2s;

public class Main {


    /**
     * Returns the big-endian {@code int} value whose byte representation is
     * the 4 bytes of <code>bytes</code> staring <code>offset</code>.
     * 
     * @param bytes
     * @param offset
     * @return int value
     */
    private static int getInt(byte[] bytes, int offset) {
        return (bytes[offset + 0] & 0xFF) << 24
                | (bytes[offset + 1] & 0xFF) << 16
                | (bytes[offset + 2] & 0xFF) << 8
                | (bytes[offset + 3] & 0xFF);
    }
}

Related Tutorials