-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_puthexa.c
48 lines (43 loc) · 1.36 KB
/
ft_puthexa.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_puthexa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mbouderr <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/11 18:26:08 by mbouderr #+# #+# */
/* Updated: 2022/11/11 21:40:07 by mbouderr ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_hex(unsigned int i, char c)
{
char *min;
char *maj;
min = "0123456789abcdef";
maj = "0123456789ABCDEF";
if (c == 'x')
{
write(1, &min[i], 1);
return (1);
}
if (c == 'X')
{
write(1, &maj[i], 1);
return (1);
}
return (0);
}
int ft_puthex(unsigned int i, char c)
{
int count;
count = 0;
if (i >= 16)
{
count += ft_puthex(i / 16, c);
count += ft_puthex(i % 16, c);
}
else if (i >= 0 && i <= 15)
count += ft_hex(i, c);
return (count);
}