Question Convert string to hex and hex to string

chinhusa

New member
Joined
Jul 31, 2023
Messages
1
Programming Experience
1-3
Hi everyone ! This first time I post here, I have a question.
I want code to convert a string Vietnamese like this “ngô_nhhi”, I want convert to hex and hex to string (result string=“ngô_nhhi” ) ?
 
What have you tried and where are you stuck? If you haven't tried anything then you haven't encountered any problems yet, so there's not really anything for us to help you with. As a clue, hexadecimal is generally used as a way to display binary data, i.e. bytes. That means that you need to convert your String to Bytes first and then to hex, which will also be a String. You will need to go via Bytes in the other direction too.
 
Look at Encoding.GetBytes to convert string to bytes: Encoding.GetBytes Method (System.Text)

Then look at Convert to convert the byte array to a hex string: Convert.FromHexString Method (System)

The same classes can be used to reverse the operation. Be sure you use the most recent version of .net for convert. If you're stuck on an older version then you'll probably use the BitConverter class instead for the forward conversion and a manual parse for the reverse (string to bytes)
 
Back
Top