C#–バイト配列を16進数へ変換するサンプルコード
代码示例
byte[] todd=new byte[]{3,5,6,9};
StringBuilder builder = new StringBuilder(length * 2);
foreach(byte value in todd)
{
char high = (char)((value >> 4) & 0x0f);
char low = (char)(value & 0x0f);
high=high<10?(high+’0′):(high-(char)10+’A’);
low=low<10?(low+’0′):(low-(char)10+’A’);
builder.Append(high);
builder.Append(low);
}
string result=builder.ToString();