The Open Source Swiss Army Knife

/programmingToolBox/comp_orgI/
/programmingToolBox/comp_orgI/ + sub-categories
http://www.sirfsup.com/
web directory content
    
      

Not logged in
Chat Register Login
return to:  http:/www.sirfsup.com      /programmingToolBox   /comp_orgI 
Permalink: hexdec.c
Title: add
article options : please login   |  raw source view  

int hextodec(char);

int main(void) {
	printf("enter the hex:");
	char * str2 = (char *)malloc(sizeof(char) * 100);
	int converted, i;
	scanf("%99s", str2);	
	int size = strlen(str2);
	printf("convert %s\n", str2);
	for (i=0; i < size; i++) {
					converted = hextodec(str2[i]);
					printf("%d",converted);
	}
	printf("\n");
}

int hextodec(char c)
{
    if (c >= '0' && c <= '9'){
	return(c - '0');
    } else if (c >= 'A' && c <= 'F'){
	return(c - 'A' + 10);
    } else if (c >= 'a' && c <= 'f'){
	return(c - 'a' + 10);
    } else
	return(-1);
}

Leave a Reply
Your Name:     anonymous
Your Email:
Website:  
Comments:

The author will be notified of your reply.
return to top