ft_ls/lib/ft_printf/ft_putnbrhex_upper_fd.c
2024-12-17 09:18:58 +01:00

37 lines
1.2 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbrhex_upper.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/14 23:24:36 by erey-bet #+# #+# */
/* Updated: 2022/11/21 19:16:57 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
u32 ft_putnbrhex_upper_fd(u32 v, u32 fd)
{
u32 tmp = 0;
u32 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 + 55);
v = v / 16;
}
tmp = count;
while (--tmp >= 0)
ft_putchar_fd(hex[tmp], fd);
return (count);
}