To check some bank account numbers I want to do a modulo 97 on an account number.
But a lot of account number is to big to enter in a UInt64.
How can I do an opperation on a 24 digits integer ?
Thanks,
Sample code (it can't convert) :
(Convert.ToUInt64("756842356987456214536254") % 97 == 1);
One way would be to use System.Numeric
's BigInteger
:
BigInteger bi = BigInteger.Parse("756842356987456214536254");
Thanks,
It's work.
Org.BouncyCastle.Math.BigInteger bi = new BigInteger("756842356987456214536254");
(Convert.ToInt32(bi.Mod(new BigInteger("97")).ToString()) == 1);
If the numbers have at most 28 digits, you can also use decimal
. This might be more convenient to use than BigInteger
.
If the input is text it could be easier to take the string and use the Encoding.GetBytes method so you get a byte array that can be passed to BigInteger constructor like this example:
var enc = new System.Text.UTF8Encoding();
var bi = new BigInteger(enc.GetBytes("756842356987456214536254"));
var result = (bi % 97).ToString();