-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_pfhex.c
39 lines (36 loc) · 1.33 KB
/
ft_pfhex.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_pfhex.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: amacarul <amacarul@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/24 11:19:39 by amacarul #+# #+# */
/* Updated: 2024/09/26 18:24:17 by amacarul ### ########.fr */
/* */
/* ************************************************************************** */
#include "libftprintf.h"
void ft_pfhex(unsigned int n, int mode, size_t *count)
{
unsigned int n_temp;
unsigned int divisor;
int digit;
char *hex_base;
n_temp = n;
divisor = 1;
while (n_temp > 15)
{
n_temp /= 16;
divisor *= 16;
}
if (mode == 1)
hex_base = "0123456789abcdef";
else if (mode == 2)
hex_base = "0123456789ABCDEF";
while (divisor > 0)
{
digit = (n / divisor) % 16;
ft_pfchar(hex_base[digit], count);
divisor /= 16;
}
}