bodacydo
bodacydo

Reputation: 79469

How to print numbers bigger than 2^32 in 32-bit C++?

I'm writing a program that generates large prime numbers. Bigger than 2^32. How do I generate such big numbers in 32-bit C++? I use Windows 7 on 32-bit processor. I know I could get 64-bit support buy buying a new 64-bit computer, but it's not an option currently.

Upvotes: 1

Views: 2155

Answers (4)

Oncaphillis
Oncaphillis

Reputation: 1908

There also is the GMP library for signed integers of arbitrary size even >2^64. The C++ interface makes the variables behave just like normal ints via operator overloading.

Upvotes: 0

bobobobo
bobobobo

Reputation: 67266

To print the number, use %lld with printf:

long long variable;
printf( "your long long variable: %lld", variable ); 

Upvotes: 2

doptimusprime
doptimusprime

Reputation: 9415

Use long long or include stdint.h or cstdint and use int64_t and uint64_t. In addition to this, you can refer to Windows data types at http://msdn.microsoft.com/en-us/library/windows/desktop/aa383751%28v=vs.85%29.aspx

From this list, you can use DWORDLONG, DWORD64 or INT64.

Upvotes: 4

Yu Hao
Yu Hao

Reputation: 122443

Use long long, which is at least 64-bit, and it's available in 32-bit machines as well.

Upvotes: 1

Related Questions