Spread the love

Convert decimal number into hexadecimal octal binary – single universal logic

 

#include <stdio.h>

char *convert(unsigned int num, int base) ;

int main( )
{
	printf("%s", convert(16,8));
	
	return 0;
}

char *convert(unsigned int num, int base) 
{
	static char buffer[33]; 
	char *ptr; 
	
	ptr = &buffer[32]; 
	*ptr = '\0'; 
	
	do 
	{ 
		*--ptr = "0123456789ABCDEF"[num%base]; 
		num /= base; 
	}while(num != 0); 
	
	return(ptr); 
}