String to Binary in C#

前端 未结 4 1377
时光说笑
时光说笑 2020-11-27 18:22

I have a function to convert string to hex as this,

public static string ConvertToHex(string asciiString)
{
    string hex = \"\";
    foreach (char c in asc         


        
4条回答
  •  天涯浪人
    2020-11-27 19:16

    The following will give you the hex encoding for the low byte of each character, which looks like what you're asking for:

    StringBuilder sb = new StringBuilder();
    foreach (char c in asciiString)
    {
        uint i = (uint)c;
        sb.AppendFormat("{0:X2}", (i & 0xff));
    }
    return sb.ToString();
    

提交回复
热议问题