How to calculate 2^n in integer where n is in between 10 to 10000 in php? Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of How to calculate 2^n in integer where n is in between 10 to 10000 in php? without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I am working with some logical problems in my localhost. At a case I need to calculate power of 2 and sum them in integer type to proceed next case. I am using 32 bit system, so I can calculate up to 2^31, as well as sum up to 2147483648 in integer type.

How can I increase the number of power up to 10000? Is there any math library or class available to calculate big integer effectively?

Probably I dont need the power over thousand but I am curious if it is possible in PHP or not. Can anyone answer my with proper reference ?

Answer

There are two libraries available in PHP to work with BIG Numbers.

They are,

  1. BC Math
  2. GMP

In both of them GMP has more library function then BC Math.

GMP – It considers leading zeros in a number string as meaning the
number is in octal, whereas ‘BC’ doesn’t. Reference:
http://www.php.net/manual/en/book.gmp.php

We are here to answer your question about How to calculate 2^n in integer where n is in between 10 to 10000 in php? - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji