How to change byte[] to hex? [duplicate]
Possible Duplicates:
How do you convert Byte Array to Hexadecimal String, and vice versa, in C#? C# byte[] to hex string
I need to take this:
byte[] data = new byte[] { 1, 2, 3, 4 }
And turn it into something like this:
0x01020304
What is the best way to do this 开发者_如何学Cin C#?
StringBuilder sb = new StringBuilder(ba.Length * 2);
foreach (byte b in ba)
{
sb.AppendFormat("{0:x2}", b)
}
return sb.ToString();
For a single value:
String.Format("{0:X2}", value);
Depending on what the array represents you can then do some string concatenating to put all the bits together.
精彩评论