Integer with 24 digits

痴心易碎 提交于 2020-01-03 10:44:12

问题


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);

回答1:


One way would be to use System.Numeric's BigInteger:

BigInteger bi = BigInteger.Parse("756842356987456214536254");



回答2:


Thanks,

It's work.

Org.BouncyCastle.Math.BigInteger bi = new BigInteger("756842356987456214536254");

(Convert.ToInt32(bi.Mod(new BigInteger("97")).ToString()) == 1);



回答3:


If the numbers have at most 28 digits, you can also use decimal. This might be more convenient to use than BigInteger.




回答4:


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();


来源:https://stackoverflow.com/questions/13508858/integer-with-24-digits

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!