Click here to Skip to main content
14,355,223 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi,

How to convert "!q44499:²о888=º88Š" to "19217134343439393AB205D0BE383838133DBA38388A". I have tried Encoding.Default.GetBytes("!q44499:²о888=º88Š"). But for character "²" I get "3f", instead of "b2".Please help.
Posted
Rate this:
Please Sign up or sign in to vote.

Solution 1

Maybe this answer would work???

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
class Convert
{

    public void DoConversion()
    {
        string str = "test";
        byte[] byteArray = null;
        System.Text.StringBuilder hexNumbers = new System.Text.StringBuilder();
        byteArray = System.Text.ASCIIEncoding.ASCII.GetBytes(str);
        for (int i = 0; i <= byteArray.Length - 1; i++) {
            hexNumbers.Append(byteArray[i].ToString("x"));
        }
        Interaction.MsgBox(hexNumbers.ToString());
        // Out  put will be 74657374

        // The following code will reverse the operation and verify the output:
        string st = hexNumbers.ToString();
        string com = "";
        for (x = 0; x <= st.Length - 1; x += 2) {
            com += Strings.ChrW(Convert.ToInt32("&H" + st.Substring(x, 2)));
        }
        Interaction.MsgBox(com);
    }
}



http://stackoverflow.com/questions/25129402/how-to-convert-ascii-to-hexdecimal-in-vb-net[^]
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 2

public static string AsciiToHex(string asciiString)
       {
           StringBuilder builder = new StringBuilder();
           foreach (char c in asciiString)
           {
               builder.Append(Convert.ToInt32(c).ToString("X"));
           }
         return builder.ToString();
       }
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100