-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_put_x_upper.c
49 lines (43 loc) · 1.35 KB
/
ft_put_x_upper.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
41
42
43
44
45
46
47
48
49
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_put_x_upper.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jorteixe <jorteixe@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/12 08:24:53 by jorteixe #+# #+# */
/* Updated: 2023/10/12 10:07:03 by jorteixe ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int ft_count_hexa(unsigned int n);
int put_x_upper(unsigned int n, int fd)
{
int counter;
counter = ft_count_hexa(n);
if (n >= 0 && n <= 15)
{
write(fd, &"0123456789ABCDEF"[n], 1);
}
else
{
put_x_upper(n / 16, fd);
put_x_upper(n % 16, fd);
}
return (counter);
}
static int ft_count_hexa(unsigned int n)
{
int counter;
counter = 0;
if (n == 0)
{
counter += 1;
}
while (n > 0)
{
n = n / 16;
counter++;
}
return (counter);
}