// 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.*;

public class WriteBin {
   public static int revbyte(int v) {
      return ((v >> 24) & 0x000000FF)
         | ((v >> 8) & 0x0000FF00)
         | ((v << 8) & 0x00FF0000)
         | ((v << 24) & 0xFF000000);
   }
   public static long revbyte(double v) {
      long v2 = Double.doubleToRawLongBits(v);
      return ((v2 >> 56) & 0x00000000000000FFL)
         | ((v2 >> 40) & 0x000000000000FF00L)
         | ((v2 >> 24) & 0x0000000000FF0000L)
         | ((v2 >> 8) & 0x00000000FF000000L)
         | ((v2 << 8) & 0x000000FF00000000L)
         | ((v2 << 24) & 0x0000FF0000000000L)
         | ((v2 << 40) & 0x00FF000000000000L)
         | ((v2 << 56) & 0xFF00000000000000L);
   }
   public static void main(String[] args) throws Exception {
      FileOutputStream fos = new FileOutputStream("C:\\javabin.dat");
      DataOutputStream dos = new DataOutputStream(fos);
      dos.writeByte("Hej med dig".length());
      dos.write("Hej med dig".getBytes("UTF-8"));
      dos.writeInt(revbyte(123));
      dos.writeBoolean(true);
      dos.writeLong(revbyte(9.9));
      dos.close();
      fos.close();
   }
}
