to Big Endian Int From Two Bytes - Java Internationalization

Java examples for Internationalization:Big Endian Little Endian

Description

to Big Endian Int From Two Bytes

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(toBigEndianIntFromTwoBytes(b, pos));
    }/* ww  w  .ja va2 s.  co m*/

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

        return (int) ret;
    }
}

Related Tutorials