Convert byte array To Short by shifting left - Android File Input Output

Android examples for File Input Output:Byte Array Convert

Description

Convert byte array To Short by shifting left

Demo Code


//package com.java2s;

public class Main {
    public static short bytesToShort(byte[] b) {
        short result = 0;
        for (short i = 0; i < 2; i++) {
            result <<= 8;/*from   www  .  j a  v a  2  s  .  c  o m*/
            result |= (b[i] & 0xFF);
        }

        return result;
    }
}

Related Tutorials