Hexadecimal representation of a byte[]

Posted on 2006-04-18
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".
Question by:m1tk4
    LVL 37

    Accepted Solution

    loop through the bytes using .ToString("x")

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

    LVL 37

    Expert Comment

    oh you also have to use a padding

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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now