Advertisement
Guest User

Untitled

a guest
Apr 11th, 2020
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.70 KB | None | 0 0
  1. using System;
  2. using System.Windows.Forms;
  3.  
  4. namespace String_To_hex
  5. {
  6.     public partial class Form1 : Form
  7.     {
  8.         public Form1()
  9.         {
  10.             InitializeComponent();
  11.         }
  12.  
  13.         private void tbString_TextChanged(object sender, EventArgs e)
  14.         {
  15.             tbHex.Clear();
  16.             char[] chars = tbString.Text.ToCharArray();
  17.             string hexString = "{";
  18.  
  19.             foreach (char currentChar in chars)
  20.             {
  21.                 string hex = Convert.ToByte(currentChar).ToString("x2").ToUpper();
  22.                 hexString += "0x" +  hex + ", ";
  23.             }
  24.  
  25.             hexString += "}";
  26.             tbHex.Text = hexString;
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement