title: Base64 Encoding Javascript to C#
body: <p>I am trying to port some Javascript to C# and I'm having a bit of trouble. The javascript I am porting calls this</p>
  
  <pre><code>var binary = out.map(function (c) {
      return String.fromCharCode(c);
  }).join("");
  return btoa(binary);
  </code></pre>
  
  <p>out is an array of numbers. I understand that it is taking the numbers and using fromCharCode to add characters to a string. At first I wasn't sure if my C# equivalent of btoa was working correctly, but the only characters I'm having issues with are the first 6 or 8. My encoded string outputs the same except for the first few characters.</p>
  
  <p>At first in C# I was doing this</p>
  
  <pre><code>String binary = "";
  foreach(int val in output){
      binary += ((char)val);
  }
  </code></pre>
  
  <p>And then I tried</p>
  
  <pre><code>foreach(int val in output){
     System.Text.ASCIIEncoding convertor = new System.Text.ASCIIEncoding();
     char o = convertor.GetChars(new byte[] { (byte)val })[0];
     binary += o;
  }
  </code></pre>
  
  <p>Both work fine on the later characters of the String but not the start. I've researched but I don't know what I'm missing.</p>
  
  <p>My array of numbers is as follows: { 10, 135, 3, 10, 182, ....}</p>
  
  <p>I know the 10s are newline characters, the 3 is end of text, the 182 is ¶, but what's confusing me is that the 135 should be the double dagger ‡. The Javascript does not show it when I print the string.</p>
  
  <p>So what ends up happening is when the String is converted to Base64 my string looks like Cj8DCj8CRFF.... while the Javascript String looks like CocDCrYCRFF.... The rest of the strings are the same and the int arrays used are identical.</p>
  
  <p>Any ideas?</p>