-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_atoi_hex.c
48 lines (44 loc) · 1.42 KB
/
ft_atoi_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
41
42
43
44
45
46
47
48
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi_hex.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmoumni <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/07/04 17:40:17 by mmoumni #+# #+# */
/* Updated: 2022/01/02 17:10:17 by mmoumni ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
int is_hexa(char c)
{
if (c == 'a' || c == 'A')
return (10);
else if (c == 'b' || c == 'B')
return (11);
else if (c == 'c' || c == 'C')
return (12);
else if (c == 'd' || c == 'D')
return (13);
else if (c == 'e' || c == 'E')
return (14);
else if (c == 'f' || c == 'F')
return (15);
return (c - 48);
}
int ft_atoi_hex(char *str)
{
int i;
int result;
i = 0;
result = 0;
while (str[i] == '0' || str[i] == 'x')
i++;
while (str[i])
{
result *= 16;
result = result + is_hexa(str[i]);
i++;
}
return (result);
}