-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_atoi_base.c
40 lines (37 loc) · 1.37 KB
/
ft_atoi_base.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_atoi_base.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kmummadi <kmummadi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/18 19:51:35 by kmummadi #+# #+# */
/* Updated: 2024/12/20 15:52:51 by kmummadi ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
#include <ctype.h>
#include <stdint.h>
uint32_t ft_atoi_base(const char *str)
{
uint32_t result;
int base;
result = 0;
base = 16;
if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X'))
str += 2;
while (*str)
{
result *= base;
if (*str >= '0' && *str <= '9')
result += *str - '0';
else if (*str >= 'a' && *str <= 'f')
result += *str - 'a' + 10;
else if (*str >= 'A' && *str <= 'F')
result += *str - 'A' + 10;
else
return (0);
str++;
}
return (result);
}