24位整数

时间:2012-11-22 08:52:43

标签: c# biginteger

要检查一些银行帐号我想在帐号上做模97。 但是很多帐号都要在UInt64中输入。

如何对24位整数进行操作?

谢谢,

示例代码(无法转换):

(Convert.ToUInt64("756842356987456214536254") % 97 == 1);

4 个答案:

答案 0 :(得分:9)

一种方法是使用System.Numeric的{​​{3}}:

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

答案 1 :(得分:1)

谢谢,

这是工作。

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

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

答案 2 :(得分:0)

如果数字最多包含28位数字,您也可以使用decimal。这可能比BigInteger更方便使用。

答案 3 :(得分:0)

如果输入是文本,则可以更容易地获取字符串并使用Encoding.GetBytes method,因此您可以获得一个可以传递给BigInteger constructor的字节数组,如下例所示:

var enc = new System.Text.UTF8Encoding();
var bi = new BigInteger(enc.GetBytes("756842356987456214536254"));
var result = (bi % 97).ToString();
相关问题