-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_cnv_hex.c
40 lines (37 loc) · 1.38 KB
/
ft_cnv_hex.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_cnv_hex.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ohachim <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/14 10:54:38 by ohachim #+# #+# */
/* Updated: 2019/03/14 10:54:40 by ohachim ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_cnv_hex(long long int adress)
{
char *hex_ray;
char *converted;
char *temp;
char *hex_char;
if (adress == 0)
{
converted = ft_make_s(1, '0');
return (converted);
}
converted = ft_strnew(1);
hex_ray = ft_strjoin("", "0123456789abcdef");
while (adress != 0)
{
hex_char = ft_make_s(1, hex_ray[adress % 16]);
temp = converted;
converted = ft_strjoin(hex_char, converted);
free(temp);
free(hex_char);
adress = adress / 16;
}
free(hex_ray);
return (converted);
}