Java Short Number Create toShort(byte[] buf, int pos)

Here you can find the source of toShort(byte[] buf, int pos)

Description

to Short

License

Apache License

Declaration

public static short toShort(byte[] buf, int pos) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static short toShort(byte[] buf, int pos) {
        return (short) (toUnsignedByte(buf, pos) << 8 + toUnsignedByte(buf, pos + 1));
    }//from   w  w w .j a  v  a2  s .  c  o  m

    public static int toUnsignedByte(byte[] buf, int pos) {
        int b = buf[pos];
        if (b < 0) {
            b = 256 + b;
        }
        return b;
    }
}

Related

  1. toShort(byte[] b)
  2. toShort(byte[] b)
  3. toShort(byte[] b)
  4. toShort(byte[] b, int off, boolean bigEndian)
  5. toShort(byte[] b, int offset)
  6. toShort(byte[] byteArray)
  7. toShort(byte[] bytes)
  8. toShort(byte[] bytes)
  9. toShort(byte[] bytes)