/*program to display hour,minute,and seconds*/
#include<stdio.h>
void times (unsigned int time);
unsigned short hours, minutes, seconds; /*global variables */
int main ()
{
int time;
puts ("enter any number(less than 24446)");
scanf ("%u", &time);
times (time);
printf ("for time=%u\n", time);
printf ("hours=%u\n", hours);
printf ("minutes=%u\n", minutes);
printf ("seconds=%u\n", seconds);
return 0;
}
void times (unsigned int time)
{
unsigned short int temp;
hours = time >> 11;
temp = time << 5;
minutes = temp >> 10;
temp = time << 11;
seconds = (time >> 11) * 2; /*why multiplying with two? */
}
I don't know where this code comes from, but it seems to come from the direction of DOS file systems or something like that.
In some of these systems, date and time are bitwise coded in two 16 bit fields, and the seconds come in a granularity of 2 s.