为什么我们将 (temp>>11) 与 2 相乘以找到此代码中的第二个

why we are multiplying (temp>>11) with 2 to find the second in this code

/*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? */
}

我不知道这段代码是从哪里来的,但它似乎来自 DOS 文件系统或类似的方向。

在其中一些系统中,日期和时间在两个 16 位字段中按位编码,秒的粒度为 2 秒。

在旧的 MSDOS 时代,文件日期和时间分别存储在一个 16 位字中。时间只精确到 2 秒以使其适合。

15–11   Hours (0–23)
10–5    Minutes (0–59)
 4–0    Seconds/2 (0–29)

15–9    Year (0 = 1980, 127 = 2107)
 8–5    Month (1 = January, 12 = December)
 4–0    Day (1–31)

代码中的左移是为了清除高位以仅留下想要的字段(本来可以做一个位掩码)。