Convert 8 Byte timestamp to a human readable time!
Mostra commenti meno recenti
I created a Matlab script that reads a file and parses out data. One data field is 8 bytes and represents a timestamp in seconds.
I browsed around and asked a few questions and came up with the following code for reading the eight bytes and converting to a time in seconds: ("this_timestamp" is the full 8 bytes of time data, file is little-endian format)
message_timestamp = typecast(uint64(hex2dec([reshape(flipud(rot90(dec2hex(this_timestamp(8:-1:5)))),1,[]),reshape(flipud(rot90(dec2hex(this_timestamp(4:-1:1)))),1,[])])),'double');
This seems to work fine under most situations, (I get the times exactly as I know they should be), but in rare circumstances the times come out as "e-310". One case this happens in is when the 8 bytes are: "00 00 00 00 00 00 5d 40" which after converting should be 116.000000.
Is there something I'm doing (or not doing) that doesn't handle data with "0"s after the decimal?
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su String Parsing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!