class HexTest
{
static char[] hexDigits = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};

public static string ToHexString(byte[] bytes) {
char[] chars = new char[bytes.Length * 2];
for (int i = 0; i < bytes.Length; i++) {
int b = bytes[i];
chars[i
* 2] = hexDigits[b >> 4];
chars[i
* 2 + 1] = hexDigits[b & 0xF];
}
return new string(chars);
}

static void Main() {
byte[] b = {0x00, 0x12, 0x34, 0x56, 0xAA, 0x55, 0xFF};
Console.WriteLine(ToHexString(b));
Console.WriteLine(BitConverter.ToString(b));//Fireworks自带方法
}
}
//运行结果
//00123456AA55FF
//00-12-34-56-AA-55-FF

相关文章:

  • 2022-12-23
  • 2021-12-19
  • 2022-12-23
  • 2021-11-06
  • 2022-12-23
  • 2021-08-03
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案