Skip to content

Instantly share code, notes, and snippets.

@benwills
Created December 27, 2014 06:26
Show Gist options
  • Select an option

  • Save benwills/62e04e86bbd7201ccc7b to your computer and use it in GitHub Desktop.

Select an option

Save benwills/62e04e86bbd7201ccc7b to your computer and use it in GitHub Desktop.
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