Skip to content

Instantly share code, notes, and snippets.

@mbohun
Created August 31, 2012 03:55
Show Gist options
  • Save mbohun/3548910 to your computer and use it in GitHub Desktop.
Save mbohun/3548910 to your computer and use it in GitHub Desktop.
uint LE/BE conversion via a value called valerie :-)
#include <stdio.h>
#include <stdint.h>
int main(int argc, char* argv[]) {
union {
uint8_t bytes[4];
uint32_t valerie;
} ub_conversion;
ub_conversion.valerie = 0xaabbccdd;
printf("0x%.2x 0x%.2x 0x%.2x 0x%.2x\n",
ub_conversion.bytes[0],
ub_conversion.bytes[1],
ub_conversion.bytes[2],
ub_conversion.bytes[3]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment