简体   繁体   中英

how to handle big integer data more than 8 byte or more than 20 digits in 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 .

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

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

Gmplib

bigint

For details, see

Arbitrary-precision_arithmetic#Libraries

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM