to Big Endian Long - Java Internationalization

Java examples for Internationalization:Charset

Description

to Big Endian Long

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;
        int width = 2;
        System.out.println(toBigEndianLong(b, pos, width));
    }/*from   w  w w .j  a v a  2  s . c  o  m*/

    public static long toBigEndianLong(byte[] b, int pos, int width) {
        long ret = 0;
        for (int i = 0; i < width; i++) {
            ret |= (b[i + pos] & 0xFFl) << (8 * (width - i - 1));
        }
        return ret;
    }
}

Related Tutorials