-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_putbin.c
38 lines (33 loc) · 1.2 KB
/
ft_putbin.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
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_base_conv.c :+: :+: */
/* +:+ */
/* By: ravan-de <[email protected]> +#+ */
/* +#+ */
/* Created: 2019/05/21 16:54:09 by ravan-de #+# #+# */
/* Updated: 2019/06/13 15:11:42 by ravan-de ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_rec(char **str, int nb, int i)
{
int rest;
if (nb > 1)
{
rest = nb % 2;
ft_rec(str, nb / 2, i + 1);
str[0][i] = rest + 48;
}
else
str[0][i] = '1';
}
void ft_putbin(int nb)
{
char *str;
str = ft_strnew(16);
ft_memset(str, 48, 16);
ft_rec(&str, nb, 0);
ft_putendl(str);
ft_strdel(&str);
}