Convert 40 bits Date Time Stamped to unix timestamp
Etienne SOBOLE (3572) 28 posts |
Hi. OS_FILE return the date of a file into Load and Execution Addresses values I thaught the code to convert the date to unix timestamp was something like this. unsigned long long date; unsigned int mktime; date = (((unsigned long long)(load_adress & 0x000000ff)) << 32) + (unsigned long long)execute_adresse; mktime = (unsigned int)(date / 100) - (unsigned int)2208988800; 2208988800 is the number for second between 01/01/1900 and 01/01/1970. 1- does anybody have the correct code to do that Thank’s |
Jeff Doggett (257) 234 posts |
As far as I can tell it looks ok to me. It’s possible that the casting isn’t working as expected. I usually look at the assembly language and it often becomes clear where the bits are getting dropped. |
Matthew Phillips (473) 721 posts |
This won’t explain the discrepancy, but you should not cast to unsigned int when all you have done is divide by 100. The result of (date / 100) will not necessarily fit in 32 bits. So your code would fail about halfway through the 2030s. |
Jeffrey Lee (213) 6048 posts |
Is execute_addresse an int? In C, casting a signed number to a larger type will sign extend the value, even if the type you’re casting to is unsigned. |
Etienne SOBOLE (3572) 28 posts |
Jeffrey, You are right Execute_adresse was an int Thank’s evetybody. |