// encode 32- bit Unicode into UTF-16
void putwchar( int c )
   {
   if ( c < 0x10000 )
      {
      // for 16-bit unicode, use 2-byte format
      int high = c >>> 8;
      int low = c & 0xff;
      putByte( high );
      putByte( low );
      }
   else
      {
      // for unicode above 0xffff use 4-byte format
      int d = c - 0x100;
      int high10 = d >>> 10;
      int low10 = d & 0x3ff;
      int highSurrogate = 0xd800 | high10;
      int lowSurrogate = 0xdc00 | low10;

      int high = highSurrogate >>> 8;
      int low = highSurrogate & 0xff;
      putByte( high );
      putByte( low );

      high = lowSurrogate >>> 8;
      low = lowSurrogate & 0xff;
      putByte( high );
      putByte( low );
      }