Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display byte array hex values?

Hi i am making application in c#.I have byte array of containing hex values.I want to to write that values as it is in file without converting it into string or anything else.Please help me.Thanks in advance.

like image 605
Dany Avatar asked Nov 23 '11 07:11

Dany


2 Answers

I'm a bit late but nobody mentioned the BitConverter class that does a little magic for you.

public static string GetHexStringFrom(byte[] byteArray)
{
  return  BitConverter.ToString(byteArray); //To convert the whole array
}

Also, there are overloads that can help parse only a part of the array

like image 196
Stefan Turcanu Avatar answered Sep 18 '22 12:09

Stefan Turcanu


You can't avoid converting it to a string if you want to display it. You can use:

String.Format("{0,10:X}", hexValue)
like image 42
Godwin Avatar answered Sep 18 '22 12:09

Godwin