Java Integer Create toInt(byte[] n)

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

Description

Converter

License

Open Source License

Parameter

Parameter Description
n a parameter

Declaration

public static int toInt(byte[] n) 

Method Source Code

//package com.java2s;
/*/*from ww  w  .j  av a 2 s .  c o m*/
 * Copyright 05-abr-2014 ?Deme
 *
 * This file is part of 'dmLang-8.1.0'.
 *
 * 'dmLang-8.1.0' 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.
 *
 * 'dmLang-8.1.0' is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY 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 Public License
 * along with 'dmLang-8.1.0'.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Converter
     *
     * @param n
     * @return
     */
    public static int toInt(byte[] n) {
        int a = n[0];
        if (a < 0) {
            a += 256;
        }
        int b = n[1];
        if (b < 0) {
            b += 256;
        }
        int c = n[2];
        if (c < 0) {
            c += 256;
        }
        int d = n[3];
        if (d < 0) {
            d += 256;
        }
        return a + b * 256 + c * 65536 + d * 16777216;
    }
}

Related

  1. toInt(byte[] data, int offset, int length)
  2. toInt(byte[] in)
  3. toInt(byte[] in)
  4. toInt(byte[] input)
  5. toInt(byte[] key)
  6. toInt(byte[] readBuffer, int o)
  7. toInt(byte[] res)
  8. toInt(byte[] si)
  9. toInt(byte[] src)