-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_utils.c
57 lines (51 loc) · 1.36 KB
/
ft_utils.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: flfische <[email protected]. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/20 00:02:58 by flfische #+# #+# */
/* Updated: 2024/03/20 00:05:40 by flfische ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_get_hexlen(unsigned int num)
{
int size;
size = 1;
while (num >= 16)
{
num /= 16;
size++;
}
return (size);
}
int ft_get_numlen(int i)
{
int size;
size = 1;
if (i == INT_MIN)
return (11);
if (i == 0)
return (1);
if (i < 0)
{
size++;
i = -i;
}
while (i >= 10)
{
i /= 10;
size++;
}
return (size);
}
int ft_power(int nb, int power)
{
if (power < 0)
return (0);
if (power == 0)
return (1);
return (nb * ft_power(nb, power - 1));
}