DateTime hex format

删除回忆录丶 提交于 2019-11-27 02:57:18

问题


I have the following know pair of hex values and dates:

7D 92 D2 5C = 26/03/2009 - 09:28
7D 92 DA CC = 27/03/2009 - 11:12
7D 92 E3 56 = 28/03/2009 - 13:22
7D 92 EC 4F = 29/03/2009 - 17:15
7D 92 F3 16 = 30/03/2009 - 12:22
7D 92 FB 1A = 31/03/2009 - 12:26
7D 93 0B 01 = 01/04/2009 - 12:01
7D 93 12 88 = 02/04/2009 - 10:08
7D 93 1A 30 = 03/04/2009 - 08:48
7D 93 22 DD = 04/04/2009 - 11:29
7D 93 2A D5 = 05/04/2009 - 11:21

I cant figure out how to convert from the one to the other....

Anyone recognise the hex format?

Al


回答1:


It's a simple bitfield, even though that's a pretty weird time format :)

1111101100100101101001001011100
                         011100 - 28 minutes
                    01001       - 09 hours
               11010            - 26 days
           0010                 - month 3 (zero-based, hence 2)
11111011001                     - 2009 years

would be my guess.




回答2:


12 bit year, 4 bit month (0-based), 5 bit day, 5 bit hour, 6 bit minute.

Nice puzzle :-)




回答3:


i realize that this is an old topic, but i found it useful and thought i would add to it my 2 cents.

u8 getMinutes(u32 in)
{
    return in & 0x3f;
}

u8 getHours(u32 in)
{
    return (in>>6) & 0x1f;
}

u8 getDays(u32 in)
{
    return (in>>11) & 0x1f;
}

u8 getMonths(u32 in)
{
    return ((in>>16)& 0xf)+1;
}

u16 getYears(u32 in)
{
    return (in>>20) & 0x7ff;
}

void printDate(u32 in)
{
    printf("%d/%d/%d - %d:%d", getDays(in), getMonths(in), getYears(in), getHours(in), getMinutes(in));
}

int main(int argc, char *argv[])
{
    u32 t = 0x7D92D25C;
    printDate(t);
    return 0;
}


来源:https://stackoverflow.com/questions/719129/datetime-hex-format

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!