ft_printf/ft_putnbrhex.c

42 lines
1.2 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbrhex.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/14 23:24:36 by erey-bet #+# #+# */
/* Updated: 2022/11/21 19:25:08 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_putnbrhex(unsigned long v)
{
int tmp;
int count;
char hex[100];
if (v == 0)
{
ft_putchar('0');
return (1);
}
count = 0;
tmp = 0;
while (v > 0)
{
tmp = v % 16;
if (tmp < 10)
hex[count++] = (tmp + 48);
else
hex[count++] = (tmp + 87);
v = v / 16;
}
tmp = count;
while (--tmp >= 0)
ft_putchar(hex[tmp]);
return (count);
}