int64 Explained

Submitted on: 1/4/2015 3:46:00 AM
By: Sartak (from psc cd)  
Level: Beginner
User Rating: By 8 Users
Compatibility: C, C++ (general), Microsoft Visual C++, Borland C++, UNIX C++
Views: 525
     This article is intended to explain the usage of 64-bit integers. It goes over how to declare them (__int64), how to use them in format functions (%I64Ld), and how to convert strings into 64-bit integers (_atoi64).

First thing's first: how to declare a 64-bit integer. You shouldn't need any header files to do this, depending on your compiler. (I use Microsoft Visual C++)

__int64 identifier;

Those are two underscores.

To use a 64-bit integer in a format function (such as sprintf or printf) we use the following format code:

For signed values: %I64Ld
For unsigned values: %I64Lu

Next: how to convert a string into a 64-bit integer. It's a pretty much like other ato* functions, which are located in stdlib.h. Here's the prototype:

__int64 _atoi64(const char *);

For example, this is how we could create and print a 64-bit integer.

int main()
__int64 NineQuintillion;
unsigned __int64 EighteenQuintillion = 18000000000000000000;

NineQuintillion = 9000000000000000000;

printf("My first 64-bit integer is %I64Ld!\n", NineQuintillion);
printf("My second 64-bit integer is %I64Lu!\n", EighteenQuintillion);

return 0;

Signed 64-bit integers have a range of:
-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

Unsigned 64-bit integers have a range of:
0 to 18,446,744,073,709,551,620
That's almost 18 and a half quintillion!

As you can see, 64-bit integers are as simple as the other data types. They don't require any snazzy functions to get the job done, they just have slightly different naming conventions. They act the same as the other number variables, so you can add, subtract, multiply, divide, and modulo divide to your heart's content. If you have any questions, or have any additional 64-bit integer information that should be included here, please, comment. :)

Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Beginner category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

 There are no comments on this submission.

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)

To post feedback, first please login.