Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store and work with Big numbers in C

Tags:

I need help working with very big numbers. According to Windows calc, the exponent

174^55 = 1.6990597648061509725749329578093e+123  

How would I store this using C (c99 standard)?

int main(){   long long int x = 174^55; //result is 153   printf("%lld\n", x); } 
like image 394
14 revs, 12 users 16% Avatar asked Apr 14 '10 20:04

14 revs, 12 users 16%


1 Answers

Normal types in C can usually only store up to 64 bits, so you'll have to store big numbers in an array, for example, and write mathematical operations yourself. But you shouldn't reinvent the wheel here - you could try the GNU Multiple Precision Arithmetic Library for this purpose.

And as the comments already pointed out, the ^ operation is binary XOR. For exponentiation, you will have to use mathematical functions like pow.

like image 142
AndiDog Avatar answered Sep 18 '22 18:09

AndiDog