-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_print_hexa.c
40 lines (37 loc) · 1.33 KB
/
ft_print_hexa.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
35
36
37
38
39
40
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_hexa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ebouabba <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/09 10:47:16 by ebouabba #+# #+# */
/* Updated: 2021/12/10 16:12:22 by ebouabba ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_print_hexa(unsigned int n, const char format)
{
int count;
count = 0;
if (n == 0)
return (write(1, "0", 1));
if (n >= 16)
{
count += ft_print_hexa(n / 16, format);
count += ft_print_hexa(n % 16, format);
}
else
{
if (n <= 9)
count += ft_print_char(n + '0');
else
{
if (format == 'x')
count += ft_print_char(n - 10 + 'a');
if (format == 'X')
count += ft_print_char(n - 10 + 'A');
}
}
return (count);
}