-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_print_hex.c
More file actions
56 lines (51 loc) · 1.48 KB
/
ft_print_hex.c
File metadata and controls
56 lines (51 loc) · 1.48 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
53
54
55
56
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_hex.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: alisharu <alisharu@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/31 17:29:21 by alisharu #+# #+# */
/* Updated: 2025/02/01 12:34:09 by alisharu ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static void fill_hex(char *hex_set, int asc)
{
int i;
char c;
char *set;
set = "0123456789abcdef";
i = 0;
while (i < 16)
{
c = set[i];
if (asc && c >= 'a' && c <= 'z')
c ^= 32;
hex_set[i] = c;
i++;
}
hex_set[i] = 0;
}
int ft_print_hex(size_t value, int asc)
{
char hex_digits[16];
int count;
char hex_set[17];
int i;
i = 0;
count = 0;
fill_hex(hex_set, asc);
if (value == 0)
{
return (ft_putchar('0'));
}
while (value != 0)
{
hex_digits[i++] = hex_set[value % 16];
value /= 16;
}
while (i--)
count += ft_putchar(hex_digits[i]);
return (count);
}