Home > Net >  C # write a large integer class, based on such can implement has a 100 - bit integer add to the high
C # write a large integer class, based on such can implement has a 100 - bit integer add to the high

Time:11-27

Write a large integer class, making based on such can implement has a 100 - bit integer add to the highest, reduction operation, and large integer comparison (including equal, greater than and less than comparison)
As far as possible concise

CodePudding user response:

Learn about c # to achieve large Numbers of calculations of large number
1, add references: System. The Numerics. DLL
2, add a namespace: using System. The Numerics;

CodePudding user response:

System. Numerics namespace

CodePudding user response:

About the source code, I am still white, still can't write it out

CodePudding user response:

According to the official documentation and examples at https://docs.microsoft.com/zh-cn/dotnet/api/system.numerics.biginteger? View=netcore - 1.0

You can use the new keyword and provide any integer or floating point values as BigInteger constructor parameters, (floating point value will be truncated before assigned to BigInteger,) the following example demonstrates how to use the new keyword to instantiate BigInteger value,

 
BigInteger bigIntFromDouble=new BigInteger (179032.6541);
Console. WriteLine (bigIntFromDouble);
BigInteger bigIntFromInt64=new BigInteger (934157136952);
Console. WriteLine (bigIntFromInt64);
//The example displays The following output:
//179032
//934157136952


You can declare a BigInteger variable and assigns a value, as well as any numeric type, if the value is the integer, this example USES the assignment from Int64 create BigInteger value

 
Long longValue=https://bbs.csdn.net/topics/6315489358112;
BigInteger assignedFromLong=longValue;
Console. WriteLine (assignedFromLong);
//The example displays The following output:
//6315489358112


You can use the BigInteger instance, just as with any other integer types, BigInteger standard digital operator overloading, to enable you to perform basic mathematical operations (such as addition, subtraction, division, multiplication and subtraction, complementation and complementation), you can also use the standard numerical operator to compare two BigInteger value

CodePudding user response:

Built-in c # class of large number may be slow, there are other code
  •  Tags:  
  • C#
  • Related