Java Byte Array to Short bytesToShort(byte[] bytes, boolean netOrder)

Here you can find the source of bytesToShort(byte[] bytes, boolean netOrder)

Description

bytes To Short

License

Open Source License

Declaration

public static short bytesToShort(byte[] bytes, boolean netOrder) 

Method Source Code

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

public class Main {
    public static short bytesToShort(byte[] bytes, boolean netOrder) {
        if (bytes == null) {
            return 0;
        }//from   w w  w.  j a  v a 2s  .co m

        return (netOrder ? (short) ((bytes[0] & 0xFF << 8) | (bytes[1] & 0xFF))
                : (short) ((bytes[1] & 0xFF << 8) | (bytes[0] & 0xFF)));
    }
}

Related

  1. bytesToShort(byte[] buf)
  2. bytesToShort(byte[] buffer, int index)
  3. bytesToShort(byte[] bytes)
  4. bytesToShort(byte[] bytes)
  5. bytesToShort(byte[] bytes)
  6. bytesToShort(byte[] bytes, int off)
  7. bytesToShort(byte[] bytes, int off, boolean bigEndian)
  8. bytesToShort(byte[] bytes, int off, int len, boolean little)
  9. bytesToShort(byte[] bytes, int offset)