Wednesday, January 28, 2009

BigInteger in C#

Usage of very large numeric or string values are common in almost all encryption procedures. For this purposes we can't use the built-in data types in c#. That's where the Biginteger data type comes to our rescue. To use BigInteger functionality in c# we have to add the reference "vjslib" from the .NET tab.After adding the reference add the namespace "using java.math" in your project. Now we are ready to play with the Big Integer functionality in our C# application.

Below is an example of BigInteger multipication:

BigInteger xyz = new BigInteger("63478364346872346874682473687346873468");
BigInteger def = new BigInteger("36537845687346583465874365843756483756");
BigInteger abc = xyz.multiply(def); // abc contains the result.

Note that the BigInteger data type accepts input as "string" from which you can typecast to any type you need. Otherwise you will get the following error :

Error 3 Cannot implicitly convert type 'int' to 'java.math.BigInteger'


No comments:

Post a Comment


Related Posts with Thumbnails