?
Solved

Hexadecimal representation of a byte[]

Posted on 2006-04-18
2
Medium Priority
?
1,231 Views
Last Modified: 2008-01-09
What's the easiest way to convert byte[] (array of bytes) to it's hexadecimal string representation ?

I.e for (1,3,10) to become "01030a".
0
Comment
Question by:m1tk4
  • 2
2 Comments
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 500 total points
ID: 16479629
loop through the bytes using .ToString("x")

                  byte [] foo = {1,2,3,27,33};
                  foreach(byte b in foo) {
                        ret += b.ToString("x");
                  }
Cheers,

Greg
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 16479656
oh you also have to use a padding

string.Format("{0:x2}", b) gives it to you.

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question