ft_ls/lib/ft_printf/ft_putnbrhex_fd.c
2024-12-16 19:35:03 +01:00

37 lines
1.3 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"
uint32_t ft_putnbrhex_fd(uint32_t v, uint32_t fd)
{
uint32_t tmp = 0;
uint32_t count = 0;
char hex[100];
if (v == 0)
return ft_putchar_fd('0', fd);
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_fd(hex[tmp], fd);
return (count);
}