Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 4.0 将字节[]转换为在C中以字符串形式存储十进制值的字符串#_C# 4.0_String Conversion - Fatal编程技术网

C# 4.0 将字节[]转换为在C中以字符串形式存储十进制值的字符串#

C# 4.0 将字节[]转换为在C中以字符串形式存储十进制值的字符串#,c#-4.0,string-conversion,C# 4.0,String Conversion,如何将字节[]转换为字符串?每次我尝试它,我都会 系统字节[] 而不是价值 另外,如何获得十进制而不是十六进制的值 使用下面的代码,我只得到十六进制 string hex = BitConverter.ToString(data); 这是我的密码 static void Main(string[] args) { Program obj = new Program(); byte[] byteData; int n; byteData = GetBytesFr

如何将
字节[]
转换为
字符串
?每次我尝试它,我都会

系统字节[]

而不是价值

另外,如何获得十进制而不是十六进制的值

使用下面的代码,我只得到十六进制

string hex = BitConverter.ToString(data);
这是我的密码

static void Main(string[] args)
{
    Program obj = new Program();
    byte[] byteData;
    int n;

    byteData = GetBytesFromHexString("001C0014500C0A5B06A4FFFFFFFFFFFFFFFFFFFFFFFFFFFF");
    n = byteData.Length;

    string s = BitConverter.ToString(byteData);
    Console.WriteLine("<Command Value='" + s + "'/>");
    Console.WriteLine("</AudioVideo>");
    Console.ReadLine();
}

public static byte[] GetBytesFromHexString(string hexString)
{
    if (hexString == null)
        return null;

    if (hexString.Length % 2 == 1)
        hexString = '0' + hexString; // Up to you whether to pad the first or last byte

    byte[] data = new byte[hexString.Length / 2];

    for (int i = 0; i < data.Length; i++)
        data[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
    Console.WriteLine(data);
    return data;
}
static void Main(字符串[]args)
{
Program obj=新程序();
字节[]字节数据;
int n;
byteData=GetBytesFromHexString(“001C0014500C0A5B06A4FFFFFFFFFFFFFFFF”);
n=字节数据长度;
字符串s=位转换器.ToString(byteData);
控制台。写线(“”);
控制台。写线(“”);
Console.ReadLine();
}
公共静态字节[]GetBytesFromHexString(字符串hexString)
{
if(hextstring==null)
返回null;
if(hexString.Length%2==1)
hexString='0'+hexString;//由您决定是填充第一个字节还是最后一个字节
字节[]数据=新字节[hexString.Length/2];
for(int i=0;i
输出应为:

0 28 0 80 12 10 91 6 164 255 255 255 255 255 255 255 255

输出应以字符串形式存储并显示。

替换该行

string s = BitConverter.ToString(byteData);


你应该很乐意去。

也为我工作
string s = string.Join(" ", byteData.Select(b => b.ToString()));