Java tutorial
//package com.java2s; import java.io.OutputStream; import java.io.IOException; public class Main { public static final int Write2(byte buf[], int ind, short v) { buf[ind] = (byte) (v & 0xff); buf[ind + 1] = (byte) ((v >> 8) & 0xff); return ind + 2; } public static final int Write2(byte buf[], int ind, int v) { buf[ind] = (byte) (v & 0xff); buf[ind + 1] = (byte) ((v >> 8) & 0xff); return ind + 2; } public static final void Write2(OutputStream out, int v) throws IOException { out.write(v & 0xff); out.write((v >> 8) & 0xff); } }