String to HexCode conversion

String to HexCode conversion

//This converts a string into Hex code
private void buttonViewAsHex_Click(object sender, System.EventArgs e)
            {
                  string hex=”";
      //Getting the textbox text and converting it to bytes
                  byte[] bytes = System.Text.ASCIIEncoding.ASCII.GetBytes(this.textBoxText.Text);
                  // bytes contains the integer values for the character code of each individual character, now you just have to convert from int to hex.
                  foreach (int i in bytes)
                  {
                        hex += ” ” + Convert.ToString(i, 16).ToUpper();
                  }
      //Adding the hexcode to the textbox 
                  this.textBoxHex.Text = hex;

            }

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.