views:

529

answers:

2

I'm curious as to if it'd be possible to convert a very, very large decimal number such as 1.67119535743*10^33/1.67119535743E+33 to hexadecimal via PHP or C#. All my previous attempts have failed, unfortunately. Thanks to all in advance!

+1  A: 

Do you mean, convert it to a hex string? You might look at bigint libraries, like this one on CodeProject.

BigInteger bi = new BigInteger("12345678901234567890");
string s = bi.ToHexString();
Michael Petrotta
A: 

I presume you're storing the number as a byte array, and want to output the hex number as a string?

This should do the job in C#:

public static string ConvertToHex(byte[] value)
{
    var sb = new System.Text.StringBuilder();
    for (int i = 0; i < sb.Length; i++)
        sb.Append(value[i].ToString("X"));

    return sb.ToString();
}
Noldorin