Ozzah
Ozzah

Reputation: 10701

BigInteger to Hexadecimal

Quick question...

I have a stupidly long BigInteger which I would like to write to a file as a hex string.

I know Java provides the .toString(16) method which does this, but I can't find an equivalent in C#.

I'm using System.Numerics.BigInteger from .NET 4.0.

Thanks

Upvotes: 15

Views: 8818

Answers (3)

artemoniks
artemoniks

Reputation: 21

yourBI.ToString("x17").Substring(1) // If you need 16 length 

Upvotes: 0

Brad
Brad

Reputation: 163232

Can you not use yourBI.ToString("X")?

http://msdn.microsoft.com/en-us/library/dd268260.aspx

Upvotes: 5

Gabe
Gabe

Reputation: 86718

Use .ToString("X") or .ToString("x") depending on what case you prefer.

Upvotes: 20

Related Questions