Java Unsigned Number Create unsignedShortBytesToInt(byte[] b)

Here you can find the source of unsignedShortBytesToInt(byte[] b)

Description

Converts an array of 2 bytes representing an unsigned short to an int containing the short value.

License

Open Source License

Parameter

Parameter Description
b an array of 4 bytes

Return

the unsigned value as a (signed) integer.

Declaration

public static int unsignedShortBytesToInt(byte[] b) 

Method Source Code

//package com.java2s;
/**/*w w w . j a  v a  2s .co m*/
 * OrbisGIS is a GIS application dedicated to scientific spatial simulation.
 * This cross-platform GIS is developed at French IRSTV institute and is able to
 * manipulate and create vector and raster spatial information.
 *
 * OrbisGIS is distributed under GPL 3 license. It is produced by the "Atelier SIG"
 * team of the IRSTV Institute <http://www.irstv.fr/> CNRS FR 2488.
 *
 * Copyright (C) 2007-2012 IRSTV (FR CNRS 2488)
 *
 * This file is part of OrbisGIS.
 *
 * OrbisGIS 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 (at your option) any later
 * version.
 *
 * OrbisGIS 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
 * OrbisGIS. If not, see <http://www.gnu.org/licenses/>.
 *
 * For more information, please consult: <http://www.orbisgis.org/>
 * or contact directly:
 * info_at_ orbisgis.org
 */

public class Main {
    /**
     * Converts an array of 2 bytes representing an unsigned short to an int containing the short value.
     * @param b an array of 4 bytes
     * @return the unsigned value as a (signed) integer.
     */
    public static int unsignedShortBytesToInt(byte[] b) {
        int i = b[1] & 0xFF;
        i <<= 8;
        i |= b[0] & 0xFF;
        return i;
    }
}

Related

  1. unsignedOneSidedGallopingIntersect2by2(final short[] smallSet, final int smallLength, final short[] largeSet, final int largeLength, final short[] buffer)
  2. unsignedShort(byte b)
  3. unsignedShort(short s)
  4. unsignedShort2Arr(int var, byte[] arrayBytes, int startIndex)
  5. unsignedShortAt(byte[] data, int pos)
  6. unsignedShortToInt(byte[] b)
  7. unsignedShortToInt(final byte[] b)
  8. unsignedShortToInt(short n)
  9. unsignedSubOverflow(int operand1, int operand2)