-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_decimal_to_hexa.c
52 lines (47 loc) · 1.47 KB
/
ft_decimal_to_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
49
50
51
52
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* decimal_to_hexa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jraymond <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/23 18:02:13 by jraymond #+# #+# */
/* Updated: 2020/02/08 13:47:44 by jraymond ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int malloc_size(int *modulos)
{
int malloc_size;
malloc_size = 0;
while (*modulos)
{
malloc_size++;
modulos++;
}
return (malloc_size + 1);
}
void ft_decimal_to_hexa(long number, char *res)
{
int modulos[30];
int index;
int index_bis;
index = -1;
index_bis = -1;
ft_bzero(modulos, 30);
if (number <= 0)
return ;
while (number)
{
modulos[++index] = number % 16;
number /= 16;
}
while (index >= 0)
{
if (modulos[index] > 9)
res[++index_bis] = 55 + modulos[index--];
else
res[++index_bis] = modulos[index--] + 48;
}
res[++index_bis] = '\0';
}