-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_bintodec.c
More file actions
38 lines (35 loc) · 1.17 KB
/
Copy pathft_bintodec.c
File metadata and controls
38 lines (35 loc) · 1.17 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_bintodec.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vlhomme <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/16 19:53:48 by vlhomme #+# #+# */
/* Updated: 2018/11/16 19:55:39 by vlhomme ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_bintodec(int nb)
{
int size;
int i;
int tmp;
int res;
size = 0;
res = 0;
tmp = nb;
while (tmp != 0)
{
tmp = tmp / 10;
size++;
}
i = 0;
while (i < size)
{
if ((nb % ft_power(10, i + 1)) != 0)
res = res + (1 * ft_power(2, i));
i++;
}
return (res);
}