-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_phexa.c
40 lines (37 loc) · 1.27 KB
/
ft_phexa.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_phexa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aizsak <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/17 09:07:11 by aizsak #+# #+# */
/* Updated: 2022/12/11 10:49:11 by aizsak ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
unsigned long ft_phexa(unsigned long n, const char type)
{
int i;
i = 0;
if (n == 0)
i += ft_pchar('0');
else if (n >= 16)
{
i += ft_phexa(n / 16, type);
i += ft_phexa(n % 16, type);
}
else
{
if (n <= 9)
i += ft_pchar(n + '0');
else
{
if (type == 'x')
i += ft_pchar(n - 10 + 'a');
else if (type == 'X')
i += ft_pchar(n - 10 + 'A');
}
}
return (i);
}