How to Find the Mth Digit of 2^n?

  • Thread starter Krypton
  • Start date
In summary, to find the mth digit of 2^n, there are several methods depending on the size of n and m. If both are small, computing 2^n and looking at the mth digit is the simplest method. If m is small, computing 2^n modulo an appropriate power of the base is recommended. For small values of n and a fast algorithm, a floating-point approximation of 2^n can be used. However, for larger values of n and m, the calculation becomes difficult due to speed and memory requirements. While it is possible to create an equation for finding the mth digit, it is not practical. Several methods have been suggested, including using integer additions or binary exponentiation, but they all have
  • #1
Krypton
13
0
How to find the mth digit of 2^n
 
Mathematics news on Phys.org
  • #2
If n is small, compute 2^n and look at the mth digit.

If m is small, compute 2^n modulo an appropriate power of your base (e.g. mod 10^9) with binary exponentiation or another efficient method.

If [itex]n\log_{10}2-m[/itex] is small, compute a floating-point approximation of 2^n with similar methods. If you're using a binary computer, this is just a base-10 conversion. If n is sufficiently small and your algorithm is fast, i.e. quasilinear, this is a good method.

Otherwise the calculation will be difficult, both because of the speed required and the memory requirements. You may need a specialized system, because I can't think of any special way to do this.
 
  • #3
Is it impossible to find an equation giving the mth digit of 2^n ?
 
  • #4
Not at all. The problem is evaluating such an equation quickly.
 
  • #5
What do u ment by not at all ? Is it not at all possible? Or not atall imposible?
 
  • #6
It's possible, but it's silly to bother. There really isn't anything special about base ten, so picking what digit is where is nothing more than a feat of clever arithmetic. Rather, I should say, creating a function which yields a specific digit is silly. Since we define base ten, we might as well pluck the damn thing out with an algorithm.
 
  • #7
Krypton said:
What do u ment by not at all ? Is it not at all possible? Or not atall imposible?

Easily possible, but pointless. The problem is how to evaluate it quickly.
 
  • #8
I found an algorithm to find the mth digit of 2^n in [itex]\mathcal O(mn^2)[/itex] time (possibly [itex]\mathcal O(mn \log n)[/itex], but I haven't proven it mathematically) using only integer additions (modulo 10). I don't know how this compares to CRGreathouse's suggestions above.
 
  • #9
Ben Niehoff said:
I found an algorithm to find the mth digit of 2^n in [itex]\mathcal O(mn^2)[/itex] time (possibly [itex]\mathcal O(mn \log n)[/itex], but I haven't proven it mathematically) using only integer additions (modulo 10). I don't know how this compares to CRGreathouse's suggestions above.

Adding 1 + 1, 2 + 2, 4 + 4, 8 + 8, (mod 10^m) ... takes n additions, each taking O(m) time, for a total of O(mn).

Multiplying 2 * 2 * ... * 2 (mod 10^m) takes n - 1 multiplications, each taking M(m) time, for a total of O(n^3) or [tex]O(n^{2.585})[/tex] with Karatsuba.

Binary exponentiation mod 10^m takes [tex]O(\lg n)[/tex] multiplications, each taking M(m) time, for a total of [tex]O(m\lg^2n)[/tex] or [tex]O(m\lg^{1.585}n)[/tex] with Karatsuba.

The latter two could be improved with FFT-based multiplications methods, but that would be silly here. The real problem is that all of these methods take somewhere around m bytes (m lg 10 bits per number, plus overhead). This can be substantial for large m.
 
  • #10
My algorithm uses at most 4n^2 bits, plus overhead, so I suppose it is worse in both time and space complexity. Oh well. :P

It's quick to do on paper, though.
 
  • #11
Would you like to describe your algorithm?
 

FAQ: How to Find the Mth Digit of 2^n?

What is the purpose of finding the Mth digit of 2^n?

The purpose of finding the Mth digit of 2^n is to identify the value of a specific digit in the result of raising 2 to the nth power. This can be useful in a variety of mathematical and scientific calculations.

How is the Mth digit of 2^n calculated?

The Mth digit of 2^n can be calculated by using the modulus operator (%) to find the remainder when 2^n is divided by 10^M. This remainder represents the Mth digit in the result.

Can the Mth digit of 2^n be negative?

No, the Mth digit of 2^n cannot be negative. Raising 2 to any power will always result in a positive value, and using the modulus operator ensures that the remainder will also be positive.

What is the largest possible value for the Mth digit of 2^n?

The largest possible value for the Mth digit of 2^n is 9. This occurs when the remainder of 2^n divided by 10^M is 9, indicating that the Mth digit is the last digit in the result (i.e. 2^n is a multiple of 10^M).

How is the Mth digit of 2^n used in real-world applications?

The Mth digit of 2^n can be used in a variety of real-world applications, such as in cryptography, computer programming, and data compression. It is also a fundamental concept in binary number systems and can be used to efficiently store and manipulate large numbers in computer systems.

Similar threads

Replies
7
Views
1K
Replies
3
Views
1K
Replies
2
Views
834
Replies
3
Views
975
Replies
34
Views
4K
Replies
1
Views
804
Replies
7
Views
2K
Replies
11
Views
1K
Replies
4
Views
895
Back
Top