How to display the hexadecimal values โ€‹โ€‹of a byte array?

Hi, I am making an application in C #. I have a byte array containing hexadecimal values. I want to write these values โ€‹โ€‹as they are in a file without converting it to a string or anything else. Please help me. Thanks in advance.

+6
source share
2 answers

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

String.Format("{0,10:X}", hexValue) 
+9
source

I'm a little late, but no one has mentioned the BitConverter class, which is a bit of magic for you.

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

In addition, there are overloads that can help parse only part of the array.

+17
source

Source: https://habr.com/ru/post/902178/


All Articles