Skip to content

Instantly share code, notes, and snippets.

@nscooling
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nscooling/974695763a8561024082 to your computer and use it in GitHub Desktop.
Save nscooling/974695763a8561024082 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <limits.h>
#include <assert.h>
#define MAGIC_NUMBER 0xFFFF7F8F
int main(void)
{
assert(sizeof(short)==2);
unsigned int ui = MAGIC_NUMBER;
unsigned short us = ui;
unsigned char uc = us;
int si = MAGIC_NUMBER;
short ss = si;
signed char sc = ss;
printf("%10u %5hu %4hhu\n", ui, us, uc);
printf("%10x %5hx %4hhx\n", ui, us, uc);
printf("%10d %5hd %4hhd\n", si, ss, sc);
printf("%10x %5hx %4hhx\n", si, ss, sc);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment