将Hex值以字节形式分配

时间:2018-11-24 03:08:03

标签: c# byte

我有这个整数(27493164),我想以这种形式将其放入字节数组:

enter image description here

我通过以下方法获得了该值:

string result = ((uint)total).ToString("X");

但是我不知道如何以这种形式将其插入字节数组。

1 个答案:

答案 0 :(得分:1)

不过,我不太确定你的措辞

// int bytes
byte[] intBytes = BitConverter.GetBytes(intValue);

//bytes to hex
var hexData = intBytes.Select(b => b.ToString("X2"))

//hex to string
Console.WriteLine(string.Join(" ",hexData));