-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathis_hex.c
More file actions
52 lines (47 loc) · 1.51 KB
/
Copy pathis_hex.c
File metadata and controls
52 lines (47 loc) · 1.51 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* is_hex.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: juhenriq <dev@juliohenrique.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/07 00:47:16 by juhenriq #+# #+# */
/* Updated: 2025/03/14 01:38:19 by juhenriq ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int check_hex(char *str, int str_len, const char *hex_characters)
{
int i;
int j;
int matches_hex_char;
matches_hex_char = 0;
i = -1;
while (++i < str_len)
{
matches_hex_char = 0;
j = -1;
while (++j < 16)
{
if (str[i] == hex_characters[j]
|| str[i] == (hex_characters[j] - 32))
{
matches_hex_char = 1;
break ;
}
}
if (!(matches_hex_char))
return (0);
}
return (1);
}
int is_hex(char *str)
{
size_t str_len;
const char *hex_characters;
if (!(str))
return (0);
hex_characters = "0123456789abcdef";
str_len = ft_strlen(str);
return (check_hex(str, str_len, hex_characters));
}