# Algorithm to find greatest significant digit of long integer

I'm doing a project euler problem (http://projecteuler.net/problem=40) that requires iteration of each digit of a set of increasing integers, in order.

I solved it by converting each integer to a string and taking the 0 index, but I'd like to know if there's a better, numerical algorithm to find the most significant digit of an arbitrarily long given integer.

Example: Given 3918287712, to easily get both (3) and find the power of 10 (10^10) that corresponds to it. I'd really like pointers to mathematical literature as well - I'm trying to increase my own knowledge of math and algorithms.

-
I do not understand. For example, are you trying to find the most significant digit of $\pi^{100000}$ (which is tough), or you have a predetermined and stored number, and you are trying to find the most significant digit of that. If the question is the latter, then how that number is stored? –  Lord Soth Jul 6 '13 at 17:17
Yes, I have a set of predefined numbers, in this case they're stored in memory as a set of long, signed integers. –  Kylar Jul 7 '13 at 14:32

Arithmetically, the number of digits of a positive integer $N$ is $d=\lfloor \log_{10} N\rfloor + 1$. For example, $\log_{10} 3918287712 \approx 9.5931$, so $3918287712$ has $\lfloor 9.5931\rfloor + 1 = 10$ digits.
Once you know the number of digits $d$ of $N$, you can find the first digit $f$ of $N$ by calculating $f = \lfloor N/10^{d-1} \rfloor$. For example, the first digit of $3918287712$ is $\lfloor 3918287712/10^{10-1} \rfloor = \lfloor 3.918287712 \rfloor = 3$.