本文整理汇总了C#中Mono.Math.BigInteger.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# BigInteger.ToString方法的具体用法?C# BigInteger.ToString怎么用?C# BigInteger.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.Math.BigInteger
的用法示例。
在下文中一共展示了BigInteger.ToString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToDecimalString
static string ToDecimalString (string hexString)
{
#if TARGET_DOTNET
throw new NotImplementedException ();
#else
// http://tools.ietf.org/html/rfc5280#section-4.1.2.2
// We SHOULD support negative numbers
var bytes = FromBinHex (hexString);
var negative = bytes.Length > 0 && bytes [0] >= 0x80;
if (negative) {
for (int i = 0; i < bytes.Length; i++)
bytes [i] = (byte) ~ bytes [i];
}
var big = new BigInteger (bytes);
if (negative) {
big = big + 1;
return "-" + big.ToString ();
} else
return big.ToString ();
#endif
}
示例2: GetTrailingZerosCount
public static int GetTrailingZerosCount(BigInteger num)
{
int count = 0;
string numAsString = num.ToString ();
int len = numAsString.Length;
for (int i = 0; i < len; i++)
{
int digit = int.Parse (numAsString[len - i - 1].ToString());
if (digit != 0)
{
break;
}
count += 1;
}
return count;
}
示例3: Convert
public static string Convert(string source, int sourceRadix, int targetRadix)
{
/* Check if radix arguments are within the allowed range. */
if (sourceRadix < MIN_RADIX || sourceRadix > MAX_RADIX)
throw new ArgumentOutOfRangeException("sourceRadix", "Source radix needs to be in a range from " + MIN_RADIX + " to " + MAX_RADIX);
if (targetRadix < MIN_RADIX || targetRadix > MAX_RADIX)
throw new ArgumentOutOfRangeException("targetRadix", "Target radix needs to be in a range from " + MIN_RADIX + " to " + MAX_RADIX);
BigInteger radixFrom = new BigInteger((UInt32)sourceRadix);
BigInteger value = new BigInteger(0);
BigInteger multiplier = new BigInteger(1);
for (int i = source.Length - 1; i >= 0; i--)
{
int digit = Digit(source[i], sourceRadix);
if (digit == -1)
throw new ArgumentException("The character '" + source[i] + "' is not defined for the source radix.", "sourceRadix");
value += multiplier * digit;
multiplier = multiplier * radixFrom;
}
return value.ToString((UInt32)targetRadix, CHARACTERS.Substring(0, targetRadix));
}