更新时间:2023-02-03 08:25:18
为此有一个内置方法:
byte[] data = { 1, 2, 4, 8, 16, 32 };
string hex = BitConverter.ToString(data);
结果:01-02-04-08-10-20
Result: 01-02-04-08-10-20
如果你想要没有破折号,只需删除它们:
If you want it without the dashes, just remove them:
string hex = BitConverter.ToString(data).Replace("-", string.Empty);
结果:010204081020
Result: 010204081020
如果你想要更紧凑的表示,你可以使用 Base64:
If you want a more compact representation, you can use Base64:
string base64 = Convert.ToBase64String(data);
结果:AQIECBAg
Result: AQIECBAg