 <h1>Benchmarks</h1> <p>Firstly, you must decide on what you mean by "best" solution, of course that takes into account the efficiency of the algorithm, its readability/maintainability, and the likelihood of bugs creeping up in the future. Careful unit tests can generally avoid those problems, however.</p> <p>I ran each of these examples 10 million times, and the results value is the number of <code>ElapsedTicks</code> that have passed.</p> <p>Without further ado, from slowest to quickest, the algorithms are:</p> <h2>Converting to a string, take first character</h2> <pre><code>int firstDigit = (int)(Value.ToString()[0]) - 48; </code></pre> <p>Results:</p> <pre><code>12,552,893 ticks </code></pre> <h2>Using a logarithm</h2> <pre><code>int firstDigit = (int)(Value / Math.Pow(10, (int)Math.Floor(Math.Log10(Value)))); </code></pre> <p>Results:</p> <pre><code>9,165,089 ticks </code></pre> <h2>Looping</h2> <pre><code>while (number &gt;= 10) number /= 10; </code></pre> <p>Results:</p> <pre><code>6,001,570 ticks </code></pre> <h2>Conditionals</h2> <pre><code>int firstdigit; if (Value &lt; 10) firstdigit = Value; else if (Value &lt; 100) firstdigit = Value / 10; else if (Value &lt; 1000) firstdigit = Value / 100; else if (Value &lt; 10000) firstdigit = Value / 1000; else if (Value &lt; 100000) firstdigit = Value / 10000; else if (Value &lt; 1000000) firstdigit = Value / 100000; else if (Value &lt; 10000000) firstdigit = Value / 1000000; else if (Value &lt; 100000000) firstdigit = Value / 10000000; else if (Value &lt; 1000000000) firstdigit = Value / 100000000; else firstdigit = Value / 1000000000; </code></pre> <p>Results:</p> <pre><code>1,421,659 ticks </code></pre> <h2>Unrolled &amp; optimized loop</h2> <pre><code>if (i &gt;= 100000000) i /= 100000000; if (i &gt;= 10000) i /= 10000; if (i &gt;= 100) i /= 100; if (i &gt;= 10) i /= 10; </code></pre> <p>Results:</p> <pre><code>1,399,788 ticks </code></pre> <p><strong>Note:</strong></p> <p>each test calls <code>Random.Next()</code> to get the next <code>int</code></p>