-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_puthex.c
63 lines (54 loc) · 1.55 KB
/
ft_puthex.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_puthex.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ofadhel <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/18 14:14:13 by ofadhel #+# #+# */
/* Updated: 2023/04/09 19:06:29 by ofadhel ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
int ft_hexlower(unsigned int nb)
{
int i;
char *hex;
hex = "0123456789abcdef";
i = 0;
if (nb >= 16)
i += ft_hexlower(nb / 16);
i += ft_putchar(hex[nb % 16]);
return (i);
}
int ft_hexupper(unsigned int nb)
{
int i;
char *hex;
hex = "0123456789ABCDEF";
i = 0;
if (nb >= 16)
i += ft_hexupper(nb / 16);
i += ft_putchar(hex[nb % 16]);
return (i);
}
int ft_hexptr(unsigned long nb)
{
int i;
char *hex;
hex = "0123456789abcdef";
i = 0;
if (nb >= 16)
i += ft_hexptr(nb / 16);
i += ft_putchar(hex[nb % 16]);
return (i);
}
int ft_pointer(unsigned long ptr)
{
int i;
i = 2;
ft_putchar('0');
ft_putchar('x');
i += ft_hexptr(ptr);
return (i);
}