-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_print_hex.c
More file actions
38 lines (35 loc) · 1.28 KB
/
ft_print_hex.c
File metadata and controls
38 lines (35 loc) · 1.28 KB
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: aycami <aycami@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/07 02:29:59 by aycami #+# #+# */
/* Updated: 2025/01/07 04:08:46 by aycami ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_print_hex(unsigned int hex, const char format)
{
int i;
i = 0;
if (hex >= 16)
{
i += ft_print_hex(hex / 16, format);
i += ft_print_hex(hex % 16, format);
}
else if (hex > 9 && format == 'x')
{
i += ft_putchar(hex - 10 + 'a');
}
else if (hex > 9 && format == 'X')
{
i += ft_putchar(hex - 10 + 'A');
}
else if (hex <= 9)
{
i += ft_putchar(hex + 48);
}
return (i);
}