For example, the following simple code shows how to use the arbitrary precision BigInteger class in C# to display a binary representation of any decimal or hex number:
using System;
using java.math;
class BignumBits {
public static void Main(String[] args)
{
BigInteger big = null;
try
{
String bnum = args[0].Trim().ToLower();
if(bnum.EndsWith("h"))
big = new BigInteger(bnum.TrimEnd('h'), 16); //base 16 input
else
big = new BigInteger(bnum); //base 10 input
}
catch(Exception)
{
Console.WriteLine("Invalid number, or no number provided");
return;
}
Console.WriteLine("\nBig Integer in binary form:\n{0}", big.toString(2)) ;
}
}
To compile using the basic .NET Framework SDK 1.1, invoke the following command:
csc.exe /r:C:\WINNT\Microsoft.NET\Framework\v1.1.4322\vjslib.dll BignumBits.cswhere the J# assembly is explicitly referenced.
Michel I. Gallant
neutron@istar.ca