Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ arbitrary length integers

Tags:

c++

int

bit

In C++, is it possible to define arbitrary length integers?

So instead of having to use uint64_t for anything in between 33 and 64 bit, I could define my own 34 bit, 36 bit, etc., integers.

like image 259
wvdz Avatar asked Apr 19 '14 08:04

wvdz


2 Answers

The compiler has its own types like you did mention. long (32 bit on most platforms) and long long (64 bit on most platforms). If you need support for larger integers, you could use different libraries which limit the size of the integer to the size of your memory.

Libraries:

  • GMPxx https://gmplib.org/manual/C_002b_002b-Class-Interface.html#C_002b_002b-Class-Interface
  • Boost Multi Precision Library www.boost.org
like image 68
schorsch_76 Avatar answered Sep 19 '22 00:09

schorsch_76


As you are living in C++ world use https://gmplib.org/

Should do the trick

like image 39
Ed Heal Avatar answered Sep 17 '22 00:09

Ed Heal