以下是c#实现
using System;
public class Program
{
void CanDecodeFromString(string str)
{
if (str.Length % 2 != 0)
return;
//OutputText(" " + "J1939:" + "\r\n");
byte[] j1939data = new byte[str.Length / 2];
for (int i = 0; i < str.Length / 2; i++)
{
j1939data[i] = System.Convert.ToByte(str.Substring(2 * i, 2), 16);
}
//J1939DataDecode(j1939data);
Console.WriteLine(String.Join("\n", j1939data));
}
public static void Main()
{
var p= new Program();
p.CanDecodeFromString("31058F410C15E1310D48312F8F41310000630220290082");
Console.WriteLine("Hello World");
}
}
的Python
hex_string="31058F410C15E1310D48312F8F41310000630220290082"
hex_data = hex_string.decode("hex")
import array
array.array('B', hex_data)
在php中,它的正确方法是什么?
示例输出
49
5
143
65
12
21
225
49
13
72
49
47
143
65
49
0
0
99
2
32
41
0
130