十六进制为Ascii转换问题 [英] Hex zeros to Ascii convertion issue

查看:99
本文介绍了十六进制为Ascii转换问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我想将Hex字符串转换为ascii。我尝试使用下面的代码,



Hi,

I want to convert Hex string to ascii. I tried using the code below,

<pre lang="c#">
public string ConvertHextoAscii(string HexString)
{
    string asciiString = "";
    for (int i = 0; i < HexString.Length; i += 2)
    {
        if (HexString.Length >= i + 2)
        {
            String hs = HexString.Substring(i, 2);
            asciiString = asciiString + System.Convert.ToChar(System.Convert.ToUInt32(HexString.Substring(i, 2), 16)).ToString();
        }
    }
    return asciiString;
}





当我将Hex002B600950000008002000010000C000009900000950转换为ascii时,它会给出\0 + + \tP \\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\给出02B609500080200100C0009900950为什么要删除零可以让任何人帮我这个?



所以我试着用互联网上的转换器转换它然后,

当我将Hex002B600950000008002000010000C000009900000950转换为ascii时它给出了?+`?P ?????????????但是当我将它转换回十六进制时它给出了3f:2b:60:3f:50:3f:3f:3f:3f:20:3f:3f:3f:3f:3f:3f:3f:3f:3f:3f:3f:50

为什么将00转换为3f?所以我不确定转换后的ascii字符串是否正确。任何人都可以帮我解决这个问题令人困惑吗?



谢谢。



when i convert Hex "002B600950000008002000010000C000009900000950" to ascii it is giving "\0+`\tP\0\0\b\0 \0\0\0À\0\0™\0\0\tP" but when i convert it to back to hex it is giving "02B609500080200100C0009900950" Why it is removing zeros can anyone help me on this?

so i try to convert this using a convertor on internet then,
when i convert Hex "002B600950000008002000010000C000009900000950" to ascii it is giving "?+`?P???? ???????????P" but when i convert it to back to hex it is giving "3f:2b:60:3f:50:3f:3f:3f:3f:20:3f:3f:3f:3f:3f:3f:3f:3f:3f:3f:3f:50"
Why is it converting the "00" to "3f"? so i''m not sure whether the converted ascii string is correct or not. It is confusing can anyone help me on this?

Thanks.

推荐答案

这个问题毫无意义。十六进制已经用ASCII编写。 (实际上,.NET基于Unicode,而不是ASCII,但ASCII可以被视为Unicode的子集,这个子集足以用于十六进制表示法。)你只是不懂术语,或者更糟。


-SA
The question makes no sense. Hex is already written in ASCII. (Actually, .NET is based on Unicode, not ASCII, but ASCII can be considered as the subset of Unicode, and this subset is enough for hexadecimal notation.) You just don''t understand the terminology, or worse.

—SA


这篇关于十六进制为Ascii转换问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆