110,539
社区成员
发帖
与我相关
我的任务
分享
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var str = "ffd8ffe0 00104a46 49460001 01000048 00480000 ffe10058 45786966 00004d4d 002a0000 00080002 01120003 00000001 00010000 87690004 00000001 00000026 00000000 0003a001 00030000 00010001 0000a002 00040000 00010000 08e0a003 00040000 00010000 05ec0000 0000ffed 00385068 6f746f73 686f7020 332e3000 3842494d 04040000 00000000 3842494d 04250000 00000010 d41d8cd9 8f00b204 e9800998 ecf8427e ffc00011 0805ec08 e0030122 00021101 031101ff c4001f00 00010501 01010101 01000000 00000000 00010203 04050607 08090a0b ffc400b5 10000201 03030204";
var bytes = HexStringToByteArray(str.Replace(" ", ""));
}
public static byte[] HexStringToByteArray(String hexString)
{
int start = 0;
if (hexString[0] == '0' && (hexString[1] == 'x' || hexString[1] == 'X'))
start = 2;
byte[] bytes = new byte[(hexString.Length - start) / 2];
for (int i = start, len = hexString.Length; i < len; i += 2)
bytes[i / 2] = Convert.ToByte(hexString.Substring(i, 2), 16);
return bytes;
}
}
}
var s = "ffd8ffe0 00104a46 49460001 01000048 00480000 ffe10058 45786966 00004d4d 002a0000 00080002 01120003 00000001 00010000 87690004 00000001 00000026 00000000 0003a001 00030000 00010001 0000a002 00040000 00010000 08e0a003 00040000 00010000 05ec0000 0000ffed 00385068 6f746f73 686f7020 332e3000 3842494d 04040000 00000000 3842494d 04250000 00000010 d41d8cd9 8f00b204 e9800998 ecf8427e ffc00011 0805ec08 e0030122 00021101 031101ff c4001f00 00010501 01010101 01000000 00000000 00010203 04050607 08090a0b ffc400b5 10000201 03030204";
var a = s.Split(' ').Select(x => (int)Convert.ToInt64(x, 16)).ToArray();
Console.WriteLine(a[1].ToString("x8")); //00104a46 验证无误