How to calculate the length of BigInteger in C#

1 Answer

0 votes
using System;
using System.Numerics;

public class Program
{
	public static void Main()
	{
		BigInteger bigInteger = BigInteger.Parse("58820136703657669922151936"); 
	
		try {
  			int length = Convert.ToInt32(Math.Ceiling(BigInteger.Log(bigInteger, 10)));
			
			Console.WriteLine("Length: " + length);
		}
		catch (ArithmeticException e) {
		  	Console.WriteLine(e.Message);
		}
	}
}



/*
run:

Length: 26

*/

 



answered Jun 9, 2024 by avibootz

Related questions

1 answer 93 views
93 views asked Jun 9, 2024 by avibootz
1 answer 92 views
1 answer 93 views
93 views asked Jun 9, 2024 by avibootz
1 answer 93 views
2 answers 118 views
2 answers 105 views
105 views asked Jun 9, 2024 by avibootz
...