C language - Handling 64-bit integers
On March 26,2022 by Tom RoutleyYou 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 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.
Intro
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 in 64-bit, therefore allowing for considerably larger numbers.
Image: © Everypixel
Article Recommendations
Latest articles
Popular Articles
Archives
- November 2024
- October 2024
- September 2024
- August 2024
- July 2024
- June 2024
- May 2024
- April 2024
- March 2024
- February 2024
- January 2024
- December 2023
- November 2023
- October 2023
- September 2023
- August 2023
- July 2023
- June 2023
- May 2023
- April 2023
- March 2023
- February 2023
- January 2023
- December 2022
- November 2022
- October 2022
- September 2022
- August 2022
- July 2022
- June 2022
- May 2022
- April 2022
- March 2022
- February 2022
- January 2022
- December 2021
- November 2021
- October 2021
- September 2021
- August 2021
- July 2021
- January 2021
Leave a Reply