If you use 64-bit integers and 32-bit integers, how long does it take to represent subtle levels of time?
#define __stdc_format_macros
#include <stdlib.h>
#include <string.h>
#include <stdio.h >
#include <inttypes.h>
#include <iostream>
using namespace std;
int main (int argc, char** argv) {
if (true) {
u_int64_t v=0xffffffffffffffff;
printf ("64bits=%" PRIu64 "us,%" PRIu64 "MS,%" PRIu64 "s,%" PRIu64 "hour,%" PRIu64 "day,%" PRIu64 "year\n", V, v/1000, v /1000000, v/1000000/3600, v/1000000/3600/24, v/1000000/3600/24/365);
}
if (true) {
u_int32_t v=0xffffffff;
printf ("32bits=%" PRIu64 "us,%" PRIu64 "MS,%" PRIu64 "s,%" PRIu64 "hour,%" PRIu64 "day,%" PRIu64 "year\n", V, v/1000, v /1000000, v/1000000/3600, v/1000000/3600/24, v/1000000/3600/24/365);
}
return 0;
}
[Winlin@dev6 temp]$ g++ test.cpp-o int64-day
[Winlin@dev6 temp]$./int64-day
64bits=18446744073709551615us, 18446744073709551ms, 18446744073709s, 5124095576hour, 213503982day, 584942year
32bits=4294967295us, 4294967ms, 4294s, 1hour, 0day, 0year
If it is used to denote milliseconds:
#define __stdc_format_macros
#include <stdlib.h>
#include <string.h>
#include <stdio.h >
#include <inttypes.h>
#include <iostream>
using namespace std;
int main (int argc, char** argv) {
if (true) {
u_int64_t v=0xffffffffffffffff;
printf ("64bits=%" PRIu64 "MS,%" PRIu64 "s,%" PRIu64 "hour,%" PRIu64 "day,%" PRIu64 "year\n", V, v/1000, v/1000/3600, V /1000/3600/24, v/1000/3600/24/365);
}
if (true) {
u_int32_t v=0xffffffff;
printf ("32bits=%" PRIu64 "MS,%" PRIu64 "s,%" PRIu64 "hour,%" PRIu64 "day,%" PRIu64 "year\n", V, v/1000, v/1000/3600, V /1000/3600/24, v/1000/3600/24/365);
}
return 0;
}
[Winlin@dev6 temp]$ g++ test.cpp-o int64-day
[Winlin@dev6 temp]$./int64-day
64BITS=18446744073709551615MS, 18446744073709551s, 5124095576030hour, 213503982334day, 584942417year
32BITS=4294967295MS, 4294967s, 1193hour, 49day, 0year