How to declare an integer that can contain huge numbers like 10 in the 20th power?

Posted on 2008-06-14
Last Modified: 2008-06-14
How to declare an integer that can contain huge numbers like 10 in the 20th power?
Question by:Chrysaor
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Expert Comment

ID: 21785050
As far as I know, a 'long int' is the largest int you can declare (doubles aside)
An 'unsigned long int is 4 bytes long. It goes from 0 to 4.294.967.295
LVL 40

Accepted Solution

evilrix earned 25 total points
ID: 21785139
>> An 'unsigned long int is 4 bytes long. It goes from 0 to 4.294.967.295
There is nothing in the C++ Standard that defines the size of an int.

"There are four signed integer types: signed char, short int, int, and long int. In this
list, each type provides at least as much storage as those preceding it in the list. Plain ints have the natural
size suggested by the architecture of the execution environment39) ; the other signed integer types are
provided to meet special needs."

The C99 Standard implements the type unsigned long long. The standard says this

 minimum value for an object of type long long int
LLONG_MIN -9223372036854775807 // -(263 - 1)

 maximum value for an object of type long long int
LLONG_MAX +9223372036854775807 // 263 - 1

 maximum value for an object of type unsigned long long int
ULLONG_MAX 18446744073709551615 // 264 - 1

Most modern C++ compilers will support this type, however, it is not defined in the C++ Standard (although this might change with C++09) and as such it isn't portable for use in C++ code.
LVL 53

Assisted Solution

Infinity08 earned 25 total points
ID: 21785289
You can always use some bignum type.
LVL 53

Expert Comment

ID: 21785292
For example :

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question