Skip to content

Instantly share code, notes, and snippets.

@strizhechenko
Created August 26, 2016 07:49
Show Gist options
  • Save strizhechenko/bbc296406db6782a2071a8ecd02d7894 to your computer and use it in GitHub Desktop.
Save strizhechenko/bbc296406db6782a2071a8ecd02d7894 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <arpa/inet.h>
struct __attribute__((__packed__)) uint24 {
uint8_t _;
uint32_t value : 24;
};
int main(void)
{
struct uint24 *s;
unsigned char a[] = {
0x1, 0x2, 0x3,
};
unsigned char *c = a;
s = (struct uint24 *)c;
printf("%u\n", htons(s->value));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment