What is the value of $2^{3000}$

975 Views Asked by At

What is the value of $2^{3000}$?

How to calculate it using a programming language like C#?

6

There are 6 best solutions below

0
On BEST ANSWER

In C# (.Net 4.0 or higher) you can obtain the desired value like this:

String result = BigInteger.Pow(2, 3000).ToString();

9
On

1230231922161117176931558813276752514640713895736833715766118029160058800614672948775360067838593459582429649254051804908512884180898236823585082482065348331234959350355845017413023320111360666922624728239756880416434478315693675013413090757208690376793296658810662941824493488451726505303712916005346747908623702673480919353936813105736620402352744776903840477883651100322409301983488363802930540482487909763484098253940728685132044408863734754271212592471778643949486688511721051561970432780747454823776808464180697103083861812184348565522740195796682622205511845512080552010310050255801589349645928001133745474220715013683413907542779063759833876101354235184245096670042160720629411581502371248008430447184842098610320580417992206662247328722122088513643683907670360209162653670641130936997002170500675501374723998766005827579300723253474890612250135171889174899079911291512399773872178519018229989376

Found using Wolfram Alpha

0
On

Here is what I got using PARI/GP by typing 2^3000

enter image description here

  • PARI is a C library, allowing fast computations.

  • gp is an easy-to-use interactive shell giving access to the PARI functions. GP is the name of gp's scripting language.

0
On

In order to avoid numerical overflow problems, some kind of arbitrary precision arithmetic is required to store numbers this large. Many computer algebra systems include arbitrary precision arithmetic.

One may also use a bignum library such as GMP. Here's a C implementation:

#include <stdio.h>
#include <gmp.h>

int main() {
  mpz_t two,two_to_the_three_thousand;

  mpz_init_set_ui(two,2);
  mpz_init(two_to_the_three_thousand);

  mpz_pow_ui(two_to_the_three_thousand,two,3000);

  gmp_printf("%Zd\n",two_to_the_three_thousand);

  mpz_clear(two);
  mpz_clear(two_to_the_three_thousand);

  return 0;
}

which we compile with gcc by:

gcc temp.c -lgmp

which outputs

1230231922161117176931558813276752514640713895736833715766118029160058800614672948775360067838593459582429649254051804908512884180898236823585082482065348331234959350355845017413023320111360666922624728239756880416434478315693675013413090757208690376793296658810662941824493488451726505303712916005346747908623702673480919353936813105736620402352744776903840477883651100322409301983488363802930540482487909763484098253940728685132044408863734754271212592471778643949486688511721051561970432780747454823776808464180697103083861812184348565522740195796682622205511845512080552010310050255801589349645928001133745474220715013683413907542779063759833876101354235184245096670042160720629411581502371248008430447184842098610320580417992206662247328722122088513643683907670360209162653670641130936997002170500675501374723998766005827579300723253474890612250135171889174899079911291512399773872178519018229989376
0
On

A MATLAB solution seems fit for I believe there are lots of MATLAB/Octave users here.

There is a Variable Precision Integer Arithmetic package in MATLAB file exchange that creates a class named vpi, and all relevant methods like power, log, etc. The usage is like MATLAB built-in uint32 or unit64. Add path to whichever folder that has this package. Type

>> A = vpi(2)^3000

>> A = 123023192216111717693155881327675251464071389573683371576611802916005 880061467294877536006783859345958242964925405180490851288418089823682358 508248206534833123495935035584501741302332011136066692262472823975688041 643447831569367501341309075720869037679329665881066294182449348845172650 530371291600534674790862370267348091935393681310573662040235274477690384 047788365110032240930198348836380293054048248790976348409825394072868513 204440886373475427121259247177864394948668851172105156197043278074745482 377680846418069710308386181218434856552274019579668262220551184551208055 201031005025580158934964592800113374547422071501368341390754277906375983 387610135423518424509667004216072062941158150237124800843044718484209861 032058041799220666224732872212208851364368390767036020916265367064113093 699700217050067550137472399876600582757930072325347489061225013517188917 4899079911291512399773872178519018229989376

And the data type of A can be retrieved by

>> class(A)

ans =vpi

Pretty useful for people working on encryption.

0
On

On a pocket calculator (using natural logs to restrict to the functions available in most computer languages), I computed $$ 3000\times\frac{\log(2)}{\log(10)}=903.089986991943 $$ I then computed $$ \exp(0.089986991943\times\log(10))=1.23023192215946 $$ Thus, getting $$ 2^{3000}=1.23023192216\times10^{903} $$ I trimmed off three digits from the mantissa since I lost three digits of significance in the log to $903$.

Not exact, but it might do in a pinch.


For a more exact answer, the following Java expression should do the trick

BigInteger("2").pow(3000).toString()