转换器十六进制

时间:2014-09-03 14:07:46

标签: c# hex ascii converter

我有一个像这样的ascii字符的文档:

~recÛßå  ^ÿìü   P       ` pÀ 0Ðÿp àÀ
```^^ÚÞâ  ^ÿòüü P      ÿ ÿà 0ÿ 0ÿÐ €
```^^ÚÞã     hÿòüü T

现在我希望将这些字符转换为十六进制字符,如下所示:

037E038D03720365036301DB01DF01E50012005EFFEC0FFC0000005000000000000000600090027001C0003001D0FF7000E003C00D036003600360035E035E01DA01DE01E20012005EFFF20FFC0FFC0050000000000000FFA0FFE002200130FFA00130FFD0012003800D036003600360035E035E01DA01DE01E300090068FFF20FFC0FFC0054等。

我的代码:

var byteArray = Encoding.UTF8.GetBytes(inputAscii);
var hexchars = "";
var i = 0;
while (i != byteArray.Length)
{
    hexchars += (byteArray[i]).ToString("X2");
}

我也尝试过var byteArray = Encoding.Default.GetBytes(inputAscii);和编码Ascii。你能帮助我吗?

1 个答案:

答案 0 :(得分:0)

试试这个:

var e = Encoding.GetEncoding("iso-8859-1");
            var bytes = Encoding.GetEncoding(1252).GetBytes("~recÛßå ^ÿìü P  pÀ 0Ðÿp àÀ^^ÚÞâ ^ÿòüü P ÿ ÿà 0ÿ 0ÿÐ € `^^ÚÞã hÿòüü T usw.");
            var s = e.GetString(bytes);

            var hexchars = "";
            for (int i = 0; i < bytes.Length; i++ )
            {
                hexchars += (bytes[i]).ToString("X2");
            }