Skip to content

Instantly share code, notes, and snippets.

@adammw
Created August 18, 2011 08:31
Show Gist options
  • Select an option

  • Save adammw/1153658 to your computer and use it in GitHub Desktop.

Select an option

Save adammw/1153658 to your computer and use it in GitHub Desktop.
pretty cool macros to work out how much space we need (in chars) for a binary number using sizeof
#define BASE2DIGITS_TO_BASE10DIGITS(a) (unsigned)((a * 2.40823997) + 1)
#define NUMDIGITS(type) BASE2DIGITS_TO_BASE10DIGITS(sizeof(type))
#define UINTBUFFERSIZE (NUMDIGITS(unsigned int) + 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment