Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Your skill will accomplish
what the force of many cannot

Binary format of time

by ccn (Vicar)
on May 26, 2009 at 06:23 UTC ( #766133=perlquestion: print w/ replies, xml ) Need Help??
ccn has asked for the wisdom of the Perl Monks concerning the following question:

Please help me to understand the binary representation of datetime.I have a program which stores time as the following:
binary data --> human readable datetime hh:mm:ss c16f b90e d17f e340 --> 01.05.09 12:47:35 5384 d5dd d27f e340 --> 01.05.09 14:09:03 1d0a 3dde d27f e340 --> 01.05.09 18:48:01 1bd8 2a11 d97f e340 --> 01.05.09 18:48:05 1b64 9211 d97f e340 --> 01.05.09 18:48:05 78d2 1182 e07f e340 --> 02.05.09 00:22:51 1cac 2682 e07f e340 --> 02.05.09 00:22:52 1cac 2682 e07f e340 --> 02.05.09 00:22:52 51d9 6182 e07f e340 --> 02.05.09 00:22:55 b74a 8982 e07f e340 --> 02.05.09 00:22:56
I'd like to be able to convert bin to txt and vice versa. I have a limited access to the program and can't just change the binary to see how time strings are changed.

I hope that it may be some standard of binary format for time. Who knows?

Update It's a PC with windows 98. I can fetch signed integer values from the log with unpack 'i', $part_of_bin_str

The program contorls a phone station and writes log messages which I want to parse and modify. I think that time granularity is far less than one second. Something like T1. The timestamp is not generated by PC but comes from phone station.

Comment on Binary format of time
Select or Download Code
Re: Binary format of time
by ysth (Canon) on May 26, 2009 at 06:37 UTC
      It's a PC with windows 98. I can fetch signed integer values from the log with unpack 'i', $part_of_bin_str

      I've updated the original post

        I can fetch signed integer values from the log ...

        Me too, but they don't correspond to the date/time in an obvious way.

        what is the name of the program/logfile?
Re: Binary format of time
by moritz (Cardinal) on May 26, 2009 at 07:14 UTC
    I think that the dates are encoded in a "least significant first" scheme, ie the year and month are encoded in the last digits, while the hours, minutes and seconds are encoded in the earlier parts of the digits.

    However, I also have my doubts, because of these two lines:

    1bd8 2a11 d97f e340 --> 01.05.09 18:48:05 1b64 9211 d97f e340 --> 01.05.09 18:48:05

    For two identical dates the first six hex digits are completely different, making me wonder if they belong to the date encoding at all.

    Are you sure that the binary data you show us actually encodes the full date?

      I suspect that time is stored in some ticks but is showed in seconds. Please see the update of original post. I am almost shure that those 8 bytes are time.

        Thinking 8 bytes and ticks you might want to try the following:

        First four bytes (0-3) | Last four bytes (4-7) --------------------------------------------------- seconds since epoch, | additional micro- e.g. 00:00 1st Jan 1970 | seconds Both four byte values are 32 bit integers.

        However, my first calculations give timestamps nowhere near the ones you provide. Maybe some CCSDS time format was used?

Re: Binary format of time
by dHarry (Monsignor) on May 26, 2009 at 08:12 UTC

    There are many "standard" binary formats for time. Some work with an offset/epoch and sometimes you have partitions as well (because of resets of the clock). This means you need extra information in order to decode it into a meaningful timestamp. It is not clear to me what format is used here. Sure you can read the bytes and interpret them as you like (un)signed int/float etc., but it's not clear how to transform this into a proper timestamp. I'm afraid more information is needed. Can you give more details on the phone station and the SW used? Why do you think the accuracy is less then a second? How did you arrive at the mapping binary -> human readable time?

Re: Binary format of time
by Anonymous Monk on May 26, 2009 at 09:14 UTC
    $ use DateTime $ my $d = DateTime->new(year => 1974, month => 11, day => 1, hour => 0 +, minute => 0, second => 0, time_zone => 'UTC') 1974-11-01T00:00:00 $ $d->clone->add(seconds => 0x40_E3_7F_D1) 2009-05-01T03:06:36 $ $d->clone->add(seconds => 0x40_E3_7F_D2) 2009-05-01T03:06:37 $ $d->clone->add(seconds => 0x40_E3_7F_D9) 2009-05-01T03:06:44 $ $d->clone->add(seconds => 0x40_E3_7F_E0) 2009-05-01T03:06:51

    That strikes near the target. Coincidence?

      That strikes near the target.
      Off by just a few hours:
      Finally in the eighth round, Ali landed the final combination, a left hook that brought Foreman's head up into position so Ali could smash him with a hard right straight to the face. Foreman staggered, then twirled across half the ring before landing on his back, he finally managed to get up but it was too late. Some argue this to have been among the greatest demonstrations of strategic planning and actual execution ever displayed in a heavyweight fight. Ali came into the fight with a tactical plan, executed it and achieved a great triumph.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://766133]
Approved by Paladin
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2014-04-17 22:08 GMT
Find Nodes?
    Voting Booth?

    April first is:

    Results (458 votes), past polls