libft/srcs/ft_puthex.c

12 lines
No EOL
301 B
C

#include "libft.h" // for ft_putchar
int ft_puthex(unsigned int n, int uppercase)
{
int count = 0;
char *digits = uppercase ? "0123456789ABCDEF" : "0123456789abcdef";
if (n >= 16)
count += ft_puthex(n / 16, uppercase);
count += ft_putchar(digits[n % 16]);
return count;
}