title: GBK Encode/Decode Charset
body: <p>I am receiving a binary packet from a server containing the following:</p>
  <pre><code>var data = new Uint8Array([0xB2, 0xE2, 0xCA, 0xD4, 0x74, 0x65, 0x73, 0x74, 0x31, 0x32, 0x33]);
  </code></pre>
  <p>I know it's a GBK charset and I am using the <a href="https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder" rel="nofollow noreferrer">TextDecoder/TextEncoder API</a> to read it back:</p>
  <pre><code>var str = TextDecoder('gbk').decode(data);
  // result: 测试test123
  </code></pre>
  <p>Now, the question : <strong>How to do the opposite ?</strong></p>
  <p>I tested :</p>
  <pre><code>var data = TextEncoder().encode(str);
  // but it doesn't match
  </code></pre>
  <p>Some handed compression:</p>
  <pre><code>(str.charCodeAt(0) &amp; 0xff) | ((str.charCodeAt(1) &gt;&gt;&gt; 8) &amp; 0xff)
  // but yeah, not need to be pro to know it can't works.
  </code></pre>
  <p>Does someone know a way to do the reverse operation ?
  Thank you in advance.</p>