Java Integer Create toInt(byte[] data)

Here you can find the source of toInt(byte[] data)

Description

Convert byte array to int

License

Open Source License

Parameter

Parameter Description
data - the byte array

Return

the int value

Declaration

public static int toInt(byte[] data) 

Method Source Code

//package com.java2s;
/**//from  ww  w.  j a  v  a2  s  .c  o  m
 * Syncnapsis Framework - Copyright (c) 2012-2014 ultimate
 * 
 * This program is free software; you can redistribute it and/or modify it under the terms of
 * the GNU General Public License as published by the Free Software Foundation; either version
 * 3 of the License, or any later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MECHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Plublic License along with this program;
 * if not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Convert byte array to int
     * 
     * @param data - the byte array
     * @return the int value
     */
    public static int toInt(byte[] data) {
        if (data == null || data.length != 4)
            return 0x0;
        // @formatter:off
        return (int) ((0xff & data[0]) << 24 | (0xff & data[1]) << 16 | (0xff & data[2]) << 8
                | (0xff & data[3]) << 0);
        // @formatter:on
    }
}

Related

  1. toInt(byte[] bytes, int offset)
  2. toInt(byte[] bytes, int offset)
  3. toInt(byte[] bytes, int offset)
  4. toInt(byte[] bytes, int offset)
  5. toInt(byte[] data)
  6. toInt(byte[] data)
  7. toInt(byte[] data, int offset, int length)
  8. toInt(byte[] in)
  9. toInt(byte[] in)