// Collection of code snippets by Arne VajhÃ¸j 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

public class BigEndianFun2 {
    public static void main(String[] args) {
        String s = "ABCabc123ÆØÅæøå";
        byte[] blittle = new byte[1000];
        ByteBuffer bblittle = ByteBuffer.wrap(blittle);
        bblittle.order(ByteOrder.LITTLE_ENDIAN);
        for(int i = 0; i < s.length(); i++) {
            bblittle.putChar(s.charAt(i));
        }
        for(int i = 0; i < bblittle.position(); i++) {
            System.out.printf(" %02X", blittle[i]);
        }
        System.out.println();
        byte[] bbig = new byte[1000];
        ByteBuffer bbbig = ByteBuffer.wrap(bbig);
        bbbig.order(ByteOrder.BIG_ENDIAN);
        for(int i = 0; i < s.length(); i++) {
            bbbig.putChar(s.charAt(i));
        }
        for(int i = 0; i < bbbig.position(); i++) {
            System.out.printf(" %02X", bbig[i]);
        }
        System.out.println();
    }
}
