64-bit integers

JellyWorld

Newbie
Joined
Mar 22, 2005
Messages
2,852
Reaction score
1
It's quite a noob question, but can you use 64-bit integers on a 32-bit CPU? I seem to be able to use long long int fine using GCC, even though according to sizeof() it's 8 bytes long. Printf only prints out the last four bytes though, not sure why.
 
I may be wrong, so take none of the following as read (I'm sure someone will step in and correct me quickly if I am)...

GCC supports the long long int type, and stores what is a 64-bit integer across 2 registers (On a 32-bit platform, obviously on a 64 bit platform it would only take up one register). sizeof() would seem to be right, as since there are 8 bits in a byte, 8 bytes would be 64 bits (8 x 8 = 64). If you had a 32-bit integer, sizeof() would come back at 4 bytes (8 x 4 = 32).

Obviously working with two registers like that to store a single integer isn't the best way of doing things though, so I'm not sure what the implications are on things like performance when it comes to handling 64-bit integers on 32-bit architecture (Since the processor has to grab information from double the number of registers).

As far as I'm aware, by default, Printf is expecting you to pass it a 4 byte int, and thus, when you pass it an 8 byte long long int, it just ignores half of it. I think there's a way to change that, but not off the top of my head.

As I said though - Could be wrong!
 
Jasoon said:
I may be wrong, so take none of the following as read (I'm sure someone will step in and correct me quickly if I am)...

GCC supports the long long int type, and stores what is a 64-bit integer across 2 registers (On a 32-bit platform, obviously on a 64 bit platform it would only take up one register). sizeof() would seem to be right, as since there are 8 bits in a byte, 8 bytes would be 64 bits (8 x 8 = 64). If you had a 32-bit integer, sizeof() would come back at 4 bytes (8 x 4 = 32).

Obviously working with two registers like that to store a single integer isn't the best way of doing things though, so I'm not sure what the implications are on things like performance when it comes to handling 64-bit integers on 32-bit architecture (Since the processor has to grab information from double the number of registers).

As far as I'm aware, by default, Printf is expecting you to pass it a 4 byte int, and thus, when you pass it an 8 byte long long int, it just ignores half of it. I think there's a way to change that, but not off the top of my head.

As I said though - Could be wrong!
As I suspected, thanks a lot!
 
Ok a little bump here.

How do you print out 64-bit integers? printf doesn't seem to like 64-bit integers.
 
Just a little side-thought - when would you ever need a number that big/that accurate?

-Angry Lawyer
 
Have you tried using the C++ way?

Code:
cout[b][color=#663300] <<[/color][/b] LongLongIntVariable[b][color=#663300];[/color][/b]
 
Marco said:
I'm surprised you haven't had the need to use integers bigger than 32 bits, yet. Here are a few examples off the top of my imaginary hat: 1) You need a very simple bit vector that is bigger than 32 bits. A 64-bit integer does just fine in this case, whereas a dedicated bit vector class might be overkill. 2) You need high accuracy when profiling high-performance/real-time applications. Usually, you measure in nanoseconds or CPU clocks, which gets you numbers that are quite large. 3) You are using integers for a coordinate system where the basic unit is small and the area to cover is large.

1) Vectors and I don't like each other very much.
2) My brain's clock runs slower than nanoseconds. Possibly.
3) Cartography is evil.

That's why :p

-Angry Lawyer
 
Angry Lawyer said:
Just a little side-thought - when would you ever need a number that big/that accurate?

-Angry Lawyer
chess Bitboards.
 
JellyWorld said:
chess Bitboards.
So that'd be vectors, as Marco said.

BTW, how's the chess program going? I'd be very interested in it as i've done Checkers and have thought about how i'd go about making a general program for those sort of games (including chess).
 
SLH said:
So that'd be vectors, as Marco said.

BTW, how's the chess program going? I'd be very interested in it as i've done Checkers and have thought about how i'd go about making a general program for those sort of games (including chess).
Its going on fine so far.
 
Back
Top