本文整理汇总了C#中BigInteger.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# BigInteger.ToString方法的具体用法?C# BigInteger.ToString怎么用?C# BigInteger.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BigInteger
的用法示例。
在下文中一共展示了BigInteger.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: digits
/*
Write a method that adds two positive integer numbers represented as
arrays of digits (each array element arr[i] contains a digit; the last
digit is kept in arr[0]). Each of the numbers that will be added
could have up to 10 000 digits.
*/
static BigInteger AddNumbers(BigInteger num1, BigInteger num2)
{
if (num1.ToString().Length < num2.ToString().Length)
{
BigInteger tempNum = num1;
num1 = num2;
num2 = tempNum;
}
char[] longerArr = num1.ToString().ToCharArray(); // Inserting the number in char array
Array.Reverse(longerArr);
char[] shorterArr = num2.ToString().ToCharArray(); // Inserting the number in char array
Array.Reverse(shorterArr);
byte[] summedNum = new byte[longerArr.Length + 1];
for (int i = 0; i < shorterArr.Length; i++)
{
byte rest = 0;
byte digitInMind = 0; // We can have only 0 or 1 in mind because we sum the digits from 0 to 9
// If the sum of the current digits is bigger than 10, we will
// have 1 in mind. In the other case we will just sum them.
if ((Convert.ToInt32(longerArr[i]) + // Subtract 96 because it sum the ASCII codes and we have two
Convert.ToInt32(shorterArr[i]) - 96) > 9) // numbers. They ASCII code of the numbers starts from 48. So 2x48
{
digitInMind = 1;
rest = (byte)((Convert.ToInt32(longerArr[i]) + Convert.ToInt32(shorterArr[i]) - 96) % 10);
}
else
{
rest = (byte)(Convert.ToInt32(longerArr[i]) + Convert.ToInt32(shorterArr[i] - 96));
}
summedNum[i] += rest; // Add the result to cell in the summed array
summedNum[i + 1] += digitInMind; // Add the "1" in mind to next cell in the summed array
}
// Adding the rest digits of the longer num
// when shorter num has no more digits.
for (int i = shorterArr.Length; i < longerArr.Length; i++)
{
summedNum[i] = (byte)(longerArr[i] - 48);
}
Array.Reverse(summedNum); // Reversing the number to get in the correct order
string result = "";
// Putting every digit in 1 string
for (int i = 0; i < summedNum.Length; i++)
{
result += summedNum[i];
}
return BigInteger.Parse(result); // Convert and return the string as number. Also removes the 0 in front.
}
示例2: ConvertToArray
private static int[] ConvertToArray(BigInteger num)
{
int[] digits = new int[num.ToString().Length];
string number = num.ToString();
BigInteger currentNumber = num;
for (int i = number.Length - 1; i >= 0; i--)
{
digits[i] = (int)(currentNumber % 10);
currentNumber /= 10;
}
return digits;
}
示例3: IntegerRepresentedAsArray
static int[] IntegerRepresentedAsArray(BigInteger number)
{
int[] numArray = new int[number.ToString().Length];
int index = 0;
foreach (char num in number.ToString())
{
numArray[index] = (int)(number % 10);
number /= 10;
++index;
}
return numArray;
}
示例4: Big
public void Big()
{
BigInteger BigInteger = new BigInteger(int.MaxValue);
BigInteger += BigInteger += BigInteger += BigInteger;
long longX = int.MaxValue;
longX += longX += longX += longX;
Assert.Equal(BigInteger.ToString(), longX.ToString());
}
示例5: DisplayTapValueAt
public void DisplayTapValueAt(Vector3 position, BigInteger value)
{
GameObject canvas = GameObject.Find("Canvas");
GameObject text = (GameObject) Instantiate(risingText);
text.transform.position = position;
text.transform.SetParent(canvas.transform);
text.GetComponent<RisingText>().Setup("+" + value.ToString(), 3f, 100f);
}
示例6: Main
static void Main(String[] args)
{
BigInteger number = new BigInteger(1);
int n = int.Parse(Console.ReadLine());
for (int i = 0; i < n; i++)
{
number = BigInteger.Multiply(number, new BigInteger(i + 1));
}
Console.WriteLine(number.ToString());
}
示例7: Main
static void Main(string[] args)
{
long value = Basics.getLong ("Ingresa un número: ");
BigInteger number = new BigInteger (value);
number = Factorial (number);
Console.WriteLine (number.ToString ("N0"));
Console.Read ();
}
示例8: NumberToArray
//converts a number to an array where the last digit is at index 0
static BigInteger[] NumberToArray(BigInteger number)
{
string numberString = number.ToString();
BigInteger[] numberArr = new BigInteger[numberString.Length];
for (int i = 0; i < numberArr.Length; i++)
{
numberArr[i] = number % 10;
number /= 10;
}
return numberArr;
}
示例9: Main
public static void Main()
{
BigInteger n = new BigInteger(1);
/* Left bit shifting is the same as raising to power of 2 */
n <<= 1000;
String s = n.ToString();
int sum = 0;
for(int i = 0, j = s.Length; i < j; sum += Int32.Parse(s.Substring(i, 1)), i++)
;
Console.WriteLine(sum);
}
示例10: FillArray
static int[] FillArray(BigInteger number)
{
string numberToString = number.ToString();
int numberLength = numberToString.Length;
int[] array = new int[numberLength];
for (int i = numberLength - 1; i >= 0; i--)
{
array[i] = (int)number % 10;
number /= 10;
}
return array;
}
示例11: InputToArray
private static int[] InputToArray(BigInteger input)
{
int[] arr = new int[input.ToString().Length];
BigInteger number = input;
int len = number.ToString().Length;
for (int i = 0; i < len; i++)
{
arr[i] = (int)number % 10;
number /= 10;
}
Array.Reverse(arr);
return arr;
}
示例12: GetN
public string GetN(int n)
{
BigInteger n0 = new BigInteger(this.a);
BigInteger n1 = new BigInteger(this.b);
BigInteger n2 = new BigInteger(0);
int i = 2;
while (i < n)
{
n2 = BigInteger.Add(BigInteger.Multiply(n1, n1), n0);
n0 = n1;
n1 = n2;
i++;
}
return n1.ToString();
}
示例13: GetHashOfPermutation
static string GetHashOfPermutation(BigInteger i)
{
List<int> numberDigits = new List<int>();
string s = i.ToString();
for (int a = 0; a < s.Length; a++)
numberDigits.Add(System.Convert.ToInt16(s.Substring(a, 1)));
numberDigits.Sort();
s = "";
foreach (int j in numberDigits)
s += j.ToString();
// Hash is the number sorted from lowest to highest value
return s;
}
示例14: VerifyCtorInt32
private static bool VerifyCtorInt32(Int32 value)
{
bool ret = true;
BigInteger bigInteger;
bigInteger = new BigInteger(value);
if (!bigInteger.Equals(value))
{
Console.WriteLine("Expected BigInteger {0} to be equal to Int32 {1}", bigInteger, value);
ret = false;
}
if (String.CompareOrdinal(value.ToString(), bigInteger.ToString()) != 0)
{
Console.WriteLine("Int32.ToString() and BigInteger.ToString() on {0} and {1} should be equal", value, bigInteger);
ret = false;
}
if (value != (Int32)bigInteger)
{
Console.WriteLine("Expected BigInteger {0} to be equal to Int32 {1}", bigInteger, value);
ret = false;
}
if (value != Int32.MaxValue)
{
if ((Int32)(value + 1) != (Int32)(bigInteger + 1))
{
Console.WriteLine("Adding 1 to both {0} and {1} should remain equal", value, bigInteger);
ret = false;
}
}
if (value != Int32.MinValue)
{
if ((Int32)(value - 1) != (Int32)(bigInteger - 1))
{
Console.WriteLine("Subtracting 1 from both {0} and {1} should remain equal", value, bigInteger);
ret = false;
}
}
Assert.True(VerifyBigintegerUsingIdentities(bigInteger, 0 == value), " Verification Failed");
return ret;
}
示例15: btnOpen_Click
private void btnOpen_Click(object sender, EventArgs e)
{
string tempKi = "";
Ki = Sign.BI_Generate_Ki();
tempKi = Ki.ToString();
try
{
Ki = new BigInteger(tempKi, 10);
find = true;
txtPrivateKey.Text = Ki.ToString();
}
catch
{
MessageBox.Show("Неверный ключ");
}
}