Reputation: 11
Need some help to determine how is this date/time being encoded Here are some examples (known date only):
2B5F0200
-> 31/10/20212B9F0200
-> 31/12/20212C3F0200
-> 31/01/2022I don't understand how this datetime format works.
Upvotes: 1
Views: 636
Reputation: 77420
First, since the last two bytes are the same in all cases, let's focus on the first two bytes. Look at them in binary:
0x2B5F: 0b_0010_1011_0101_1111 0x2B9F: 0b_0010_1011_1001_1111 0x2C3F: 0b_0010_1100_0011_1111
Next, consider the binary representation for the numbers in the dates. In some date formats, months are 0-based (January is 0), in others they're 1-based, so include both.
21: 0b_1_0101 22: 0b_1_0110 10: 0b_1010, 0b_1001 12: 0b_1010, 0b_1001 01: 0b_0001, 0b_0000 31: 0b_1_1111
By inspection, each of these binary numerals appears in the appropriate date. 31 is the last 5 bits. The next 4 bits are 10, 12 and 1. 21 and 22 show up in the first 7 bits (for 100 years, you'll need at least 7 bits).
21 10 31 0x2B5F: 0b_0010101_1010_11111 21 12 31 0x2B9F: 0b_0010101_1100_11111 22 1 31 0x2C3F: 0b_0010110_0001_11111
The format is thus a packed bit-field:
0 1 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 +-------------+-------+---------+ | year (YY) | month | day | +-------------+-------+---------+
Or, as bit masks:
year: 0xFE00 month: 0x01E0 day: 0x001F
Upvotes: 1