Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to handle big integer data more than 8 byte or more than 20 digits in c++

Tags:

c++

size of integer is 4,long long int is 8 byte and it can access about 19 digits data and for unsigned long long int size also 8 byte but handle larger value than long long int but this is less than 20 digits.Is there any way that can handle over 20 digits data.

#include<iostream>
using namespace std;
int main()
{
    unsigned long long int a;//any data type more than 8 byte can handle
    cin>>a;
    if(a>789456123789456123123)//want to take a higher thand this digits
    {
        cout<<"a is larger and big data"<<endl;
    }
}

I searched about it for a while but didn't find helpful contents.All about is java biginteger.

like image 512
Sofi Ullah Saikat Avatar asked Apr 30 '16 07:04

Sofi Ullah Saikat


2 Answers

There are no built-in types larger than unsigned long long in C++.

You have 2 options:

  • Use a library which supports "BigInts" (for example gmp)
  • Implement your own "BigInt" class
like image 198
Rakete1111 Avatar answered Sep 27 '22 23:09

Rakete1111


you can use library to implement that. many libraries are availabe. such as:

Gmplib

bigint

For details, see

Arbitrary-precision_arithmetic#Libraries

like image 32
Faojul Ahsan Avatar answered Sep 27 '22 23:09

Faojul Ahsan