如何在php中将十六进制字符串转换为字节数组
下面是c#实现如何在php中将十六进制字符串转换为字节数组,php,hex,Php,Hex,下面是c#实现 using System; public class Program { void CanDecodeFromString(string str) { if (str.Length % 2 != 0) return; //OutputText(" " + "J1939:" + "\r\n"); byte[] j1939data = new b
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");
}
}
在php中,什么是正确的方法
样本输出
49
5
143
65
12
21
225
49
13
72
49
47
143
65
49
0
0
99
2
32
41
0
130
样本输出是什么?[0x31,0x05,0x8F…]?49 5 143 65 12 21 225 49 13 72 49 47 143 65 49 0 99 2 32 41 0 130Hi,您知道如何将长十六进制字符串转换为字节数组?示例输出是什么?[0x31,0x05,0x8F…]?49 5 143 65 12 21 225 49 13 72 49 47 143 65 49 0 99 2 32 41 0 130Hi,您知道如何将长十六进制字符串转换为字节数组了吗?
49
5
143
65
12
21
225
49
13
72
49
47
143
65
49
0
0
99
2
32
41
0
130