10

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.

2 Answers 2

28

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

Sign up to request clarification or add additional context in comments.

1 Comment

Note that BitConverter adds "-" marks in between the bytes. Make sure to remove those if you don't want them :)
10

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.