convert byte to hex

Hi all,

I have a byte data and I would like to convert to hex.

byte noOfByte = data[5];

May I know how to do that?

I had come across this

System.Globalization.NumberStyles.HexNumber

but not sure how to do that.

Can someone please help?

[575 byte] By [bslim] at [2008-1-9]
# 1
When looking for ways to display information in specific formats, the first place to look is the ToString() method of the datatype you're dealing with.

In your case you can use noOfByte.ToString("X") do display the hex value. (i.e. "E" for 14)

StevePy at 2007-10-2 > top of Msdn Tech,Visual C#,Visual C# General...
# 3

Code Snippet

using System;

class Program
{
static void Main()
{
byte[] x = {10, 20, 30, 40};
string hex = BitConverter.ToString(x);
Console.WriteLine(hex); // 0A-14-1E-28
}
}

nikov at 2007-10-2 > top of Msdn Tech,Visual C#,Visual C# General...