What is the data type that i should use to store a 33 digit wide number.
I am using unsigned long long
but overflow occurs.How to deal with it?
Asked
Active
Viewed 205 times
0

MSalters
- 173,980
- 10
- 155
- 350

user3283576
- 33
- 6
-
2Strictly speaking this is a subset. `char[33]` is a reasonable answer here, but unsuited for arithmetic. – MSalters Dec 11 '14 at 15:45
-
1When you are saying "digit" what do you mean? Binary? Hexadecima? Decimal? – Eugene Sh. Dec 11 '14 at 15:58
-
i am talking about decimal.. – user3283576 Dec 12 '14 at 07:40
1 Answers
1
__int128
on GCC allows you to store numbers up to 170141183460469231731687303715884105727
, with 39 digits.

vz0
- 32,345
- 7
- 44
- 77
-
1Isn't that `unsigned __int128`? https://gcc.gnu.org/onlinedocs/gcc/_005f_005fint128.html – pmg Dec 11 '14 at 15:52
-
@pmg (1<<128) - 1 = (1<<0) + (1<<1) + (1<<2) + ... + (1<<127) = 340282366920938463463374607431768211455. – vz0 Dec 11 '14 at 15:54
-
1
-
-
Remark: This is not portable; most other compilers do not provide a built in 128 bit type. – fuz Dec 11 '14 at 17:03
-
which header file do i need to include for that??? and how can i print this number using printf?? – user3283576 Dec 11 '14 at 19:00