-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_btoi.c
32 lines (29 loc) · 1.1 KB
/
ft_btoi.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_btoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abassibe <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/04/17 14:28:08 by abassibe #+# #+# */
/* Updated: 2018/03/14 03:25:40 by abassibe ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_btoi(char *str)
{
int len;
int ret;
int pow;
len = ft_strlen(str) - 1;
ret = 0;
pow = 0;
while (len >= 0)
{
if (str[len] == '1')
ret += ft_power(2, pow);
pow++;
len--;
}
return (ret);
}