Algorithm to shorten 6-digit time stamp if possible?

Astro

New member
Joined
Jun 19, 2013
Messages
3
Hi All,
a time stamp is a 6-digit word: hh-mm-ss (h: hour, m: minute, s: second). Ex: 20:01:45.
Is it possible to reduce it to a smaller digit format which contains the same unique and incremental information given by the original 6-digit one?
Ex:
20:01:45 --> 136;
20:01:46 --> 137;
20:01:47 --> 138;
...
You may focus on mm:ss part whose range is 00-59:00-59 and together requires 4 digits. Each 00-59 (mm) can pair with a corresponding 00-59 (ss).
The only way I can imagine is a change of base. However, I don't want to use chars other than digits to represent this data. So, if I am thinking to hexadecimal system for example, it can't help. I am not familiar with other bases. Maybe you can help.
Negative numbers may help to half the number of digits but 60/2=30 is still a 2-digit number and all together I get 4 digits again.
Do you know any way to make it?
Thanks
Ricardo
 
Hi All,
a time stamp is a 6-digit word: hh-mm-ss (h: hour, m: minute, s: second). Ex: 20:01:45.
Is it possible to reduce it to a smaller digit format which contains the same unique and incremental information given by the original 6-digit one?
Ex:
20:01:45 --> 136;
20:01:46 --> 137;
20:01:47 --> 138;
...
You may focus on mm:ss part whose range is 00-59:00-59 and together requires 4 digits. Each 00-59 (mm) can pair with a corresponding 00-59 (ss).
The only way I can imagine is a change of base. However, I don't want to use chars other than digits to represent this data. So, if I am thinking to hexadecimal system for example, it can't help. I am not familiar with other bases. Maybe you can help.
Negative numbers may help to half the number of digits but 60/2=30 is still a 2-digit number and all together I get 4 digits again.
Do you know any way to make it?
Thanks
Ricardo
The most straightforward thing to do is count seconds since midnight. The number of seconds in a day is 86400.
N = 3600*h + 60*m + s
To convert N back to time, you can find h as the integer part of N/3600, m as the integer part of (N - 3600h)/60, and s the remainder of that division.

Operationally, this is somewhat like choosing base 60 - but writing the number in the decimal system.

Dropping down to the binary system, You would need 5 bits for h, 6 bits for m, and 6 bits for s. That makes a 17-bit word which could be masked to extract h, m, and s.
 
@DrPhil & @Denis

Thank you.
DrPhil's post reminded me that hh:mm:ss is already a base 60 which is well-known but something I overlooked...
With K = 3600*h + 60*m + s

and reverse operations:
K = Kth second of day

h = FLOOR(K / 3600)
m = FLOOR[(K - 3600h / 60]
s = K - 3600h - 60m

h,m and s are all 2-digit each. Therefore, I end up with 6 digits overall. I aim to reduce the number of digits needed to represent K (if possible?). I tried with a linear combination (summing up each member of K, i.e. h, m and s multiplied by different coefficients) but all I get is a range of 2-digit numbers repeating itself each time the original base 60 sequence restarts. That means I am loosing the property of uniqueness the original format guarantees. In other words, there happen multiple collisions...
My hope was to focus on mm:ss part in order to make it a 2-digit instead of actual 4-digit and charge hh up which is 0-23 but could be extended to 0-99 to bear some of collisions with no increment in its number of digits.
I guess a mathematical formulation of the problem would reveal the limits of any attempts made to reduce the original format to a shorter one.
Thanks you again.
 
Assuming a 32 bit word, you can store a time stamp identifying year of the decade, day of the year, hour, minute, and second in a single word.

There are, considering leap years, less than 10 * 366 * 24 * 60 * 60 = 316,224,000 seconds in a decade.

The largest number storable in a 32-bit word (considering 1 bit as a sign bit) is 2,147,483,648.

Of course you may mean characters, not words. Using base 62, you can do time stamps for a year using just three characters.
 
Assuming a 32 bit word, you can store a time stamp identifying year of the decade, day of the year, hour, minute, and second in a single word.

There are, considering leap years, less than 10 * 366 * 24 * 60 * 60 = 316,224,000 seconds in a decade.

The largest number storable in a 32-bit word (considering 1 bit as a sign bit) is 2,147,483,648.

Of course you may mean characters, not words. Using base 62, you can do time stamps for a year using just three characters.


Dear JeffM,
jeah, actually I mean characters not words.
With regards to your tip about using base 62, could you please advise a sort of pseudo algorithm to transform my present base 60 (DAILY 6 digit) clock into a base 62 (YEARLY 3 digit) one?
Thanks in advance!
 
Top