operating and printing with 64-bit numbers

Discussion to talk about software related topics only.
Post Reply
vsabino
Posts: 32
Joined: Wed May 14, 2008 8:45 am

operating and printing with 64-bit numbers

Post by vsabino »

Hi,

I'm trying to work with 64-bit numbers.

I declared my variable as "long long": long long decimal_place;

then I assign it a value: decimal_place = 1000000000000; // The 1 exp 12 is the largest decimal place for a 40-bit number

but I get a compiler error: integer constant is too large for 'long' type.

Why?

After I get this resolved, I want to print the value to the screen.
How do I that?

Thanks,
Victor
kevin_d_mccall
Posts: 11
Joined: Thu May 22, 2008 5:36 am

Re: operating and printing with 64-bit numbers

Post by kevin_d_mccall »

Try adding an 'L' after the constant you are trying to load into the long value as the compiler is trying to store it into an integer.

decimal_place = 1000000000000L;
jchapman
Posts: 1
Joined: Thu Jun 26, 2008 7:39 am

Re: operating and printing with 64-bit numbers

Post by jchapman »

I don't think that a single "L" will work since that is only 32 bits (also the size of int on 32-bit architectures).
To tell the compiler that your constant is 64 bits, you need to append two "L"s like so:

long long i = 5000000000LL;
Post Reply