You may need to
handle very large numbers in the C language. An unsigned number of 32 bits cannot exceed a particular value. In order to handle larger integers, a separate data type for
handling 64 bit integers can be used in the C programming language. The long long data type can handle large integers by allowing the C language compiler to store the number in two registers instead of one. To print a
long long data type, the formatting for display is different from other data types. The long long data type makes
handling 64 bit integers easy.
[C language]Handling 64-bit integers
Basically in C language, an unsigned number over 32 bits cannot exceed the value of 4,294,967,295.
You may find you are required to handle larger numbers and for this you need these numbers to be coded in 64-bit.
However, this is not handled in the same way as an ordinary integer. They must be defined differently.
Unsigned 64-bit integer
Type: unsigned long long
Formatting for display: % llu
Suffix to define a constant: ULL
Example:
//Assign the value in a 4294967296
unsigned long long a= 4294967296ULL;
//Show the value
printf ( "% llu", a);
Signed 64-bit integer
Type: long long
Formatting for display: % lld
Suffix to define a constant: LL
Example:
//Assign the value in a 4294967296
long long a= 4294967296LL;
// Show the value
printf ( "% lld", a);
Using an unusual suffix to define a constant value
Unsigned long long a = 4294967296
Your compiler will prompt you that this number is too large for the "long" type. This concept is directly related to the architecture of 32-bit processors. A 32-bit processor is limited and your default compiler will try to fit the numbers in one registry. But with a suffix such as LL and ULL, your compiler will store your number on 2 registers, i.e. in 64-bit, therefore allowing for considerably larger numbers.
See also
Knowledge communities.
Published by
netty5 -
Latest update by Paul Berentzen