Skip to content

Instantly share code, notes, and snippets.

@ebibibi
Created June 28, 2012 14:19
Show Gist options
  • Select an option

  • Save ebibibi/3011644 to your computer and use it in GitHub Desktop.

Select an option

Save ebibibi/3011644 to your computer and use it in GitHub Desktop.
putxval
#include <stdio.h>
/* 数値の16進表示 */
int putxval(unsigned long value, int column)
{
char buf[9];
char *p;
p = buf + sizeof(buf) -1;
*(p--) = '\0';
if(!value && !column)
column++;
while (value || column) {
*(p--) = "0123456789abcdef"[value & 0xf];
value >>= 4;
if (column) column--;
}
printf("%s\n", p+1);
return 0;
}
int main(void)
{
putxval(0x10, 0);
putxval(0xffff, 0);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment