Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BigInteger to Hexadecimal

Tags:

c#

hex

biginteger

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

like image 902
Ozzah Avatar asked Feb 14 '11 04:02

Ozzah


People also ask

How do I change BigInteger to string?

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.

How do I convert BigInteger to long?

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.

How do I get BigInteger value?

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.


2 Answers

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

like image 50
Gabe Avatar answered Oct 27 '22 00:10

Gabe


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

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

like image 38
Brad Avatar answered Oct 26 '22 23:10

Brad