Calculating 64-Bit Values
I hope this is not a really stupid question, but Ive tried some ways and I'm still not satisfied with my current solution. I have to calculate some 64 Bit values, like this:
typedef unsigned long long int64;
int64 val = 0x7c95674beb4000;
the only working way to perform calculation was this:
unsigned int timestamp[2];
timestamp[1] = (unsigned int)((int64)val+0x4324154)); timestamp[0] = (int64)((int64)val+0x4324154)) >> 32;
And printing the value works like this:
printf("Value: %8lx%8lx\n", timestamp[0], timestamp[1]);
Does anyone know a better way to get along with these 64Bit-values?
Thanks in advance,
Jonas
Quoted 3 lines
typedef unsigned long long int64;
int64 val =
0x7c95674beb4000;
Try:
int64 val = 0x7c95674beb4000ll;
gcc won't generate a long long constant unless you explictly tell it to; it tries to stuff the whole thing into 32 bits, which doesn't really work.
Incidentally, you might want to pick a different name for your typedef -- int64 is usually signed.
Quoted 3 lines
And printing the value works like this:
printf("Value: %8lx%8lx\n", timestamp[0], timestamp[1]);
printf("Value: %llx", timestamp);
should work. You may need %qx instead of %llx on some really old systems, or conceivably %Lx.
Steven Smith.