* Calculating 64-Bit Values
@ 2004-05-13 13:49 Jonas Appel
2004-05-13 14:30 ` Steven Smith
0 siblings, 1 reply; 2+ messages in thread
From: Jonas Appel @ 2004-05-13 13:49 UTC (permalink / raw)
To: linux-c-programming
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Calculating 64-Bit Values
2004-05-13 13:49 Calculating 64-Bit Values Jonas Appel
@ 2004-05-13 14:30 ` Steven Smith
0 siblings, 0 replies; 2+ messages in thread
From: Steven Smith @ 2004-05-13 14:30 UTC (permalink / raw)
To: Jonas Appel; +Cc: linux-c-programming, sos22
[-- Attachment #1: Type: text/plain, Size: 631 bytes --]
> 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.
> 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.
[-- Attachment #2: Type: application/pgp-signature, Size: 187 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-05-13 14:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-05-13 13:49 Calculating 64-Bit Values Jonas Appel
2004-05-13 14:30 ` Steven Smith
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).