Java Byte Array to Short bytesToShort(byte[] bytes, int off, boolean bigEndian)

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

Description

bytes To Short

License

Open Source License

Declaration

public static short bytesToShort(byte[] bytes, int off, boolean bigEndian) 

Method Source Code

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

public class Main {
    public static short bytesToShort(byte[] bytes, int off, boolean bigEndian) {
        byte b1 = bytes[off], b2 = bytes[off + 1];
        if (!bigEndian) {
            byte tmp = b1;
            b1 = b2;//w  w  w . j a  v a 2s . c  o  m
            b2 = tmp;
        }
        return (short) (((b1 & 0xFF) << 8) | (b2 & 0xFF));
    }
}

Related

  1. bytesToShort(byte[] bytes)
  2. bytesToShort(byte[] bytes)
  3. bytesToShort(byte[] bytes)
  4. bytesToShort(byte[] bytes, boolean netOrder)
  5. bytesToShort(byte[] bytes, int off)
  6. bytesToShort(byte[] bytes, int off, int len, boolean little)
  7. bytesToShort(byte[] bytes, int offset)
  8. bytesToShort(byte[] bytes, int start)
  9. bytesToShort(byte[] bytes, int startIndex)