-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_print_hex.c
43 lines (39 loc) · 1.36 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
39
40
41
42
43
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_hex.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jede-ara <jede-ara@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/29 16:06:07 by jede-ara #+# #+# */
/* Updated: 2022/12/02 17:19:51 by jede-ara ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
/*
DESCRIÇÃO: print_hex() imprime um número em formato hexadecimal em minúsculas
e maiúsculas.
*/
int ft_print_hex(unsigned int n, int c)
{
int count;
count = 0;
if (n >= 16)
{
count += ft_print_hex(n / 16, c);
count += ft_print_hex(n % 16, c);
}
else
{
if (n <= 9)
count += ft_putchar((n + '0'));
else
{
if (c == 'x')
count += ft_putchar((n - 10 + 'a'));
if (c == 'X')
count += ft_putchar((n - 10 + 'A'));
}
}
return (count);
}