[ create a new paste ] login | about

Link: http://codepad.org/McJl3JiP    [ raw code | output | fork ]

C, pasted on Jul 14:
#include <stdio.h>
#include <stdlib.h>

int ishex (char c)
{
int i = 0;
char *list = "0123456789AaBbCcDdEeFf";
while (list[i]!='\0') {
	if (c==list[i++]) return 1;
	}
return 0;
}

int main (void)
{
char str[256], tmp[2] = {0};
int i = 0, d;

printf("16進数を入力してください\n>");
fgets(str, 256, stdin);

while (1) {
	tmp[0] = str[i++];
	if (!ishex(tmp[0])) break;
	d = strtol(tmp, NULL, 16);
	fputc((d&8)?'1':'0', stdout);
	fputc((d&4)?'1':'0', stdout);
	fputc((d&2)?'1':'0', stdout);
	fputc((d&1)?'1':'0', stdout);
	fputc(' ', stdout);
	}

return 0;
}


Output:
1
2
16進数を入力してください
>


Create a new paste based on this one


Comments: