-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_hexa.c
50 lines (45 loc) · 1.37 KB
/
ft_hexa.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_hexa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fsalem <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/22 14:06:23 by fsalem #+# #+# */
/* Updated: 2023/02/05 14:31:03 by fsalem ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int hex_len(unsigned int n)
{
int len;
len = 0;
if (n == 0)
return (1);
while (n != 0)
{
len++;
n = n / 16;
}
return (len);
}
int ft_hexa(unsigned int n, char spot)
{
int hexa_len;
hexa_len = hex_len(n);
if (n >= 16)
{
ft_hexa(n / 16, spot);
ft_hexa(n % 16, spot);
}
else if (n <= 9)
ft_character(n + '0');
else if (n > 9 && n < 16)
{
if (spot == 'x')
ft_character(n - 10 + 'a');
if (spot == 'X')
ft_character(n - 10 + 'A');
}
return (hexa_len);
}