// 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.io.ByteArrayOutputStream;
import java.io.DataOutputStream;

public class IntToBytes {
   public static void main(String[] args) throws Exception {
      short v = 9600;
      byte[] b1 = new byte[2];
      b1[0] = (byte)(v / 256);
      b1[1] = (byte)(v % 256);
      System.out.println(b1[0] + " " + b1[1]);
      byte[] b2 = new byte[2];
      b2[0] = (byte)((v  >> 8) & 0xFF);
      b2[1] = (byte)(v & 0xFF);
      System.out.println(b2[0] + " " + b2[1]);
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      DataOutputStream dos = new DataOutputStream(baos);
      dos.writeShort(v);
      dos.flush();
      byte[] b3 = baos.toByteArray();
      System.out.println(b3[0] + " " + b3[1]);
   }
}
