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
BigInteger. toString() method returns the decimal String representation of this BigInteger. This method is useful to convert BigInteger to String. One can apply all string operation on BigInteger after applying toString() on BigInteger.
longValue() converts this BigInteger to a long. This conversion is analogous to a narrowing primitive conversion from long to int. If this BigInteger is too big to fit in a long, only the low-order 64 bits are returned.
BigInteger intValue() Method in Java Returns: The method returns an int value which represents integer value for this BigInteger. Examples: Input: BigInteger1=32145 Output: 32145 Explanation: BigInteger1. intValue()=32145.
Use .ToString("X")
or .ToString("x")
depending on what case you prefer.
Can you not use yourBI.ToString("X")
?
http://msdn.microsoft.com/en-us/library/dd268260.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With