Repository navigation
Expand file tree
/
Copy pathserver_utils.c
More file actions
56 lines (50 loc) · 1.4 KB
/
Copy pathserver_utils.c
File metadata and controls
56 lines (50 loc) · 1.4 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* server_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gsap <gsap@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/07/26 13:15:53 by gsap #+# #+# */
/* Updated: 2021/07/29 11:47:48 by gsap ### ########.fr */
/* */
/* ************************************************************************** */
#include "server.h"
void ft_putchar(char c)
{
write (1, &c, 1);
}
void ft_putnbr(int n)
{
if (n > 9)
{
ft_putnbr(n / 10);
ft_putchar((n % 10) + '0');
}
else
ft_putchar(n + '0');
}
int ft_recursive_power(int nb, int power)
{
if (power < 0)
return (0);
if (power == 0)
return (1);
if (power > 1)
nb *= ft_recursive_power(nb, power - 1);
return (nb);
}
int ft_bin_to_dec(char *s)
{
int i;
int res;
res = 0;
i = 0;
while (s[i])
{
if (s[i] == '1')
res += ft_recursive_power(2, (7 - i));
i++;
}
return (res);
}