-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_print_hex.c
34 lines (31 loc) · 1.19 KB
/
ft_print_hex.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_hex.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vcodrean <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/29 09:48:57 by vcodrean #+# #+# */
/* Updated: 2023/01/03 13:59:53 by vcodrean ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_print_hex(unsigned int nr, char *base)
{
int nr_base[16];
int i;
int result;
i = 0;
result = 0;
if (nr == 0)
result += ft_putchar('0');
while (nr)
{
nr_base[i] = nr % 16;
nr = nr / 16;
i++;
}
while (--i >= 0)
result += ft_putchar(base[nr_base[i]]);
return (result);
}