-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_print_hex.c
38 lines (35 loc) · 1.28 KB
/
ft_print_hex.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_hex.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: skarras <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/25 15:38:35 by skarras #+# #+# */
/* Updated: 2024/11/25 15:38:36 by skarras ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int print_hex(unsigned long long nb, char type)
{
int count;
count = 0;
if (nb >= 16)
{
count += print_hex(nb / 16, type);
count += print_hex(nb % 16, type);
}
else
{
if (nb < 10)
count += print_char(nb + '0');
else
{
if (type == 'x')
count += print_char((nb - 10) + 'a');
else if (type == 'X')
count += print_char((nb - 10) + 'A');
}
}
return (count);
}