byte[]轉換成16進制字符串的高效方法或算法

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);
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章