title: string values to byte array without converting
body: <p>I'm trying to put the values of a string into a byte array with out changing the characters. This is because the string is in fact a byte representation of the data. </p>
  
  <p>The goal is to move the input string into a byte array and then convert the byte array using:</p>
  
  <pre><code>string result = System.Text.Encoding.UTF8.GetString(data);
  </code></pre>
  
  <p>I hope someone can help me although I know it´s not a very good description.</p>
  
  <p>EDIT:
  And maybe I should explain that what I´m working on is a simple windows form with a textbox where users can copy the encoded data into it and then click preview to see the decoded data. </p>
  
  <p>EDIT: 
  A little more code:
  (inputText is a textbox)</p>
  
  <pre><code>    private void button1_Click(object sender, EventArgs e)
      {
          string inputString = this.inputText.Text;
          byte[] input = new byte[inputString.Length];
          for (int i = 0; i &lt; inputString.Length; i++)
          {
              input[i] = inputString[i];
          }
          string output = base64Decode(input);
          this.inputText.Text = "";
          this.inputText.Text = output;
      }
  </code></pre>
  
  <p>This is a part of a windows form and it includes a rich text box. This code doesn´t work because it won´t let me convert type char to byte. 
  But if I change the line to :</p>
  
  <pre><code>    private void button1_Click(object sender, EventArgs e)
      {
          string inputString = this.inputText.Text;
          byte[] input = new byte[inputString.Length];
          for (int i = 0; i &lt; inputString.Length; i++)
          {
              input[i] = (byte)inputString[i];
          }
          string output = base64Decode(input);
          this.inputText.Text = "";
          this.inputText.Text = output;
      }
  </code></pre>
  
  <p>It encodes the value and I don´t want that. I hope this explains a little bit better what  I´m trying to do.</p>
  
  <p>EDIT: The  base64Decode function:</p>
  
  <pre><code>    public string base64Decode(byte[] data)
      {
          try
          {
              string result = System.Text.Encoding.UTF8.GetString(data);
              return result;
          }
          catch (Exception e)
          {
              throw new Exception("Error in base64Decode" + e.Message);
          }
      }
  </code></pre>
  
  <p>The string is not encoded using base64 just to be clear. This is just bad naming on my behalf.</p>
  
  <p>Note this is just one line of input.</p>
  
  <p>I've got it. The problem was I was always trying to decode the wrong format. I feel very stupid because when I posted the example input I saw this had to be hex and it was so from then on it was easy. I used this site for reference:
  <a href="http://msdn.microsoft.com/en-us/library/bb311038.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/bb311038.aspx</a></p>
  
  <p>My code:</p>
  
  <pre><code>     public string[] getHexValues(string s)
       {
          int j = 0;
          string[] hex = new String[s.Length/2];
          for (int i = 0; i &lt; s.Length-2; i += 2)
          {
              string temp = s.Substring(i, 2);
              this.inputText.Text = temp;
              if (temp.Equals("0x")) ;
              else
              {
                  hex[j] = temp;
                  j++;
              }
          }
          return hex;
      }
  
      public string convertFromHex(string[] hex)
      {
          string result = null;
          for (int i = 0; i &lt; hex.Length; i++)
          {
              int value = Convert.ToInt32(hex[i], 16);
              result += Char.ConvertFromUtf32(value);
          }
          return result;
      }
  </code></pre>
  
  <p>I feel quite dumb right now but thanks to everyone who helped, especially @Jon Skeet.</p>