-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_printhex.c
45 lines (41 loc) · 1.28 KB
/
ft_printhex.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printhex.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: amait-ou <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/17 12:58:16 by amait-ou #+# #+# */
/* Updated: 2023/01/24 00:07:58 by amait-ou ### ########.fr */
/* */
/* ************************************************************************** */
#include "./superlib.h"
static int ft_numlen_int(t_ul nb)
{
int i;
i = 0;
if (nb == 0)
++i;
while (nb > 0)
{
++i;
nb /= 16;
}
return (i);
}
int ft_printhex(t_ul address, char *s)
{
if (address == 0)
{
ft_putchar('0');
return (1);
}
if (address > 15)
{
ft_printhex(address / 16, s);
ft_putchar(s[address % 16]);
}
else
ft_putchar(s[address % 16]);
return (ft_numlen_int(address));
}