Formula:
512 * (year - 1980) +32 * month + day
Why do we multiply 512 with year?
and why do we multiply 32 with month?
Formula:
512 * (year - 1980) +32 * month + day
Why do we multiply 512 with year?
and why do we multiply 32 with month?
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.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Because DOS uses a 16 bits encoding:
day from 0x01 (1) to 0x1f (31) -- 5 bitsCode:Bit: 111111 5432109 8765 43210 year month day
month from 0x01 (1) to 0x0c (12) - 4 bits:
year: remaining 7 bits.