Java Short Number Create toShort(byte[] b, int off, boolean bigEndian)

Here you can find the source of toShort(byte[] b, int off, boolean bigEndian)

Description

to Short

License

Open Source License

Declaration

public static short toShort(byte[] b, int off, boolean bigEndian) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static short toShort(byte[] b, int off, boolean bigEndian) {
        if (bigEndian) {
            return (short) (((b[0] & 0xff) << 8) | (b[1] & 0xff));
        } else {//from  www .  ja v a  2s  .  com
            return (short) (((b[1] & 0xff) << 8) | (b[0] & 0xff));
        }
    }

    public static void toShort(short[] s, int sOff, byte[] b, int bOff, int bLen, boolean bigEndian) {
        int bEnd = bOff + bLen;
        for (int j = bOff, k = sOff; j < bEnd; j += 2, k++) {
            s[k] = toShort(b, j, bigEndian);
        }
    }
}

Related

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