Skip to content

Instantly share code, notes, and snippets.

@kylehowells
Created February 27, 2015 02:09
Show Gist options
  • Select an option

  • Save kylehowells/46389fc58d21cb2f6f75 to your computer and use it in GitHub Desktop.

Select an option

Save kylehowells/46389fc58d21cb2f6f75 to your computer and use it in GitHub Desktop.
Get an uint16_t that was stored in an uint8_t* array.
// uint8_t *buffer [1] & [2] contain the uint16_t bytes.
uint16_t duration;
uint8_t* p = (uint8_t*)(void*)&duration;
*p = buffer[1]; // 2e
*(p+1) = buffer[2]; // e5
//duration now contains 2ee5
printf("duration: %d", duration);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment