Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert number to hex

Status
Not open for further replies.

rico14d

Programmer
Apr 8, 2002
135
GB
Hi,

I'm trying to convert a number to its hex value which i can do with-
System.Convert.ToInt32(12323)

However, the number im trying to convert is much bigger (a MD5 hash result - 975415459309518814222848482335161230234) and the function errors.

Any ideas anyone.

Rich.
 
Also, you may want to check out the Microsoft.VisualBasic.Hex class


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
The ComputeHash method on the MD5 class returns a byte array. What you can do is take each pair of bytes and convert them into a hex value:
Code:
  int i = 0;  
     // get bytes 0 and 1
  int16 bytePair = BitConverter.ToInt16(byteArray, i);
     // zero-pad the hex number!
  string hexString = bytePair.ToString("X02");
You'd then just loop thru your byte pairs, and concatenate your hex values together into one big string.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top