Java Short Number Create toShort(byte... b)

Here you can find the source of toShort(byte... b)

Description

to Short

License

GNU General Public License

Declaration

public static short toShort(byte... b) 

Method Source Code

//package com.java2s;
/**// w w  w.  ja  v a  2 s  .co m
 * License
 * 
 * Licensed under the GNU GPL v3
 * http://www.gnu.org/licenses/gpl.html
 * 
 */

public class Main {

    public static short toShort(byte... b) {
        return (short) toLong(b);
    }

    public static long toLong(byte... b) {
        long l = 0;
        int len = b.length;
        for (int i = 0; i < len && i < 8; i++) {
            l = (long) l << 8 | byte2UnsignInt(b[i]);
        }
        return l;
    }

    public static int byte2UnsignInt(byte b) {
        if (b >> 1 == b >>> 1)
            return b;
        else
            return 256 + b;
    }
}

Related

  1. toShort(byte a, byte b)
  2. toShort(byte b0, byte b1)
  3. toShort(byte byte0, byte byte1)
  4. toShort(byte mostSignificant, byte leastSignificant)
  5. toShort(byte msb, byte lsb)
  6. toShort(byte... b)
  7. toShort(byte[] b)
  8. toShort(byte[] b)
  9. toShort(byte[] b)