本文整理匯總了C#中System.Numerics.BigInteger.Abs方法的典型用法代碼示例。如果您正苦於以下問題:C# BigInteger.Abs方法的具體用法?C# BigInteger.Abs怎麽用?C# BigInteger.Abs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Numerics.BigInteger
的用法示例。
在下文中一共展示了BigInteger.Abs方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
//引入命名空間
using System;
using System.IO;
using System.Numerics;
using System.Runtime.Serialization.Formatters.Binary;
[Serializable] public struct SignAndMagnitude
{
public int Sign;
public byte[] Bytes;
}
public class Example
{
public static void Main()
{
FileStream fs;
BinaryFormatter formatter = new BinaryFormatter();
BigInteger number = BigInteger.Pow(Int32.MaxValue, 20) * BigInteger.MinusOne;
Console.WriteLine("The original value is {0}.", number);
SignAndMagnitude sm = new SignAndMagnitude();
sm.Sign = number.Sign;
sm.Bytes = BigInteger.Abs(number).ToByteArray();
// Serialize SignAndMagnitude value.
fs = new FileStream(@".\data.bin", FileMode.Create);
formatter.Serialize(fs, sm);
fs.Close();
// Deserialize SignAndMagnitude value.
fs = new FileStream(@".\data.bin", FileMode.Open);
SignAndMagnitude smRestored = (SignAndMagnitude) formatter.Deserialize(fs);
fs.Close();
BigInteger restoredNumber = new BigInteger(smRestored.Bytes);
restoredNumber *= sm.Sign;
Console.WriteLine("The deserialized value is {0}.", restoredNumber);
}
}
輸出:
The original value is -4.3510823966323432743748744058E+186. The deserialized value is -4.3510823966323432743748744058E+186.