Created
December 27, 2014 06:26
-
-
Save benwills/62e04e86bbd7201ccc7b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| unsigned short timestamp = <some value>; // Bits: DDDDDHHHHHMMMMMM | |
| int day = (timestamp >> 11) & 0x1F; | |
| int hour = (timestamp >> 6) & 0x1F; | |
| int min = (timestamp) & 0x3F; | |
| unsigned short dup_timestamp = (short)((day << 11) | (hour << 6) | min); | |
| // Alternative using macros | |
| #define DAY(x) (((x) >> 11) & 0x1F) | |
| #define HOUR(x) (((x) >> 6) & 0x1F) | |
| #define MINUTE(x) ((x) & 0x3F) | |
| #define TIMESTAMP(d, h, m) ((((d) & 0x1F) << 11) | (((h) & 0x1F) << 6) | ((m) & 0x3F) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment