# Thread: Date representation into DOS/Window

1. ## Date representation into DOS/Window

Formula:

512 * (year - 1980) +32 * month + day

Why do we multiply 512 with year?
and why do we multiply 32 with month? 2. They're packed as bits in a 16-bit integer
yyyyyyymmmmddddd

There are at most 31 days. The next highest power of 2 is 32, which gives the multiplier of 32 for month.

There are 12 months. The next highest power of 2 is 16, which gives the multiplier of 512 (aka 32*16) for year. 3. Because DOS uses a 16 bits encoding:
Code:
```Bit: 111111
5432109 8765   43210
year    month  day```
day from 0x01 (1) to 0x1f (31) -- 5 bits
month from 0x01 (1) to 0x0c (12) - 4 bits:
year: remaining 7 bits. 4. Originally Posted by Salem They're packed as bits in a 16-bit integer
yyyyyyymmmmddddd
They are packed in 32 bits according to my textbook.
How does it will work for 32 bits? 5. Originally Posted by rm82co They are packed in 32 bits according to my textbook.
How does it will work for 32 bits?
512*(year-1980)+32*month+day is equivalent to (year-1980) << 9 | month << 5 | day

512 and 32 are powers-of-two. multiplying by them is the direct equivalent of a bitwise "shift left" operation. 1980 is simply this date system's "epoch".

I think it is like this. Popular pages Recent additions date, date in window, date representation, date storing, multiply 