-
Notifications
You must be signed in to change notification settings - Fork 1
/
hexa.c
48 lines (42 loc) · 1.37 KB
/
hexa.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hexa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: glasset <glasset@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/10/28 12:57:10 by glasset #+# #+# */
/* Updated: 2016/10/31 14:52:56 by glasset ### ########.fr */
/* */
/* ************************************************************************** */
#include "nm.h"
static void init(char **str, int len)
{
int i;
i = 0;
while (i < (len + 1))
{
(*str)[i++] = '0';
}
(*str)[i] = '\0';
}
static int gen_hexa(unsigned long n, char **str, int i)
{
unsigned int a;
unsigned int u;
char *val;
val = "0123456789abcdef";
u = 0;
a = n % 16;
n = n / 16;
if (n > 0)
u = u + gen_hexa(n, str, (i - 1));
(*str)[i] = val[a];
u++;
return (u);
}
int ft_hexa(unsigned long n, char **str, int i)
{
init(str, i);
return (gen_hexa(n, str, i));
}