char c = (char) ((b1 << 8) | b2);
char c = (char) (((b1 & 0xFF) << 8) | (b2 & 0xFF));
  protected CoderResult decodeLoop (ByteBuffer in, CharBuffer out)  {    // TODO: Optimize this in the case in.hasArray() / out.hasArray()    int inPos = in.position ();    try      {        while (in.remaining () >= 2)          {            byte b1 = in.get ();            byte b2 = in.get ();            // handle byte order mark            if (byteOrder == UNKNOWN_ENDIAN)              {                char c = (char) ((b1 << 8) | b2);                if (c == BYTE_ORDER_MARK)                  {                    byteOrder = BIG_ENDIAN;                    inPos += 2;                    continue;                  }                else if (c == REVERSED_BYTE_ORDER_MARK)                  {                    byteOrder = LITTLE_ENDIAN;                    inPos += 2;                    continue;                  }                else                  {                    // assume big endian, do not consume bytes,                    // continue with normal processing                    byteOrder = BIG_ENDIAN;                  }              }            char c = byteOrder == BIG_ENDIAN ? (char) ((b1 << 8) | b2)                                             : (char) ((b2 << 8) | b1);            if (0xD800 <= c && c <= 0xDFFF)              {                // c is a surrogate                                // make sure c is a high surrogate                if (c > 0xDBFF)                  return CoderResult.malformedForLength (2);                if (in.remaining () < 2)                  return CoderResult.UNDERFLOW;                byte b3 = in.get ();                byte b4 = in.get ();                char d = byteOrder == BIG_ENDIAN ? (char) ((b3 << 8) | b4)                                                 : (char) ((b4 << 8) | b3);                // make sure d is a low surrogate                if (d < 0xDC00 || d > 0xDFFF)                  return CoderResult.malformedForLength (2);                out.put (c);                out.put (d);                inPos += 4;              }            else              {                if (!out.hasRemaining ())                  return CoderResult.UNDERFLOW;                out.put (c);                inPos += 2;              }          }        return CoderResult.UNDERFLOW;      }    finally      {        in.position (inPos);      }  }