Onion
Onion

Reputation: 177

Converting very large decimal numbers to hexadecimal (1.67119535743*10^33)

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!

Upvotes: 0

Views: 1457

Answers (2)

Noldorin
Noldorin

Reputation: 147280

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();
}

Upvotes: 0

Michael Petrotta
Michael Petrotta

Reputation: 60902

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();

Upvotes: 1

Related Questions