to Big Endian Short - Java Internationalization

Java examples for Internationalization:Charset

Description

to Big Endian Short

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        byte[] b = new byte[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 };
        int pos = 2;
        System.out.println(toBigEndianShort(b, pos));
    }/*from   w w  w.j  av a  2s .co  m*/

    public static short toBigEndianShort(byte[] b, int pos) {
        short ret = 0;
        ret |= (b[pos] & 0xFF) << 8;
        ret |= (b[pos + 1] & 0xFF);
        return ret;
    }
}

Related Tutorials