-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_pfptrhex.c
42 lines (39 loc) · 1.37 KB
/
ft_pfptrhex.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_pfptrhex.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: amacarul <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/24 16:21:38 by amacarul #+# #+# */
/* Updated: 2024/09/27 10:43:43 by amacarul ### ########.fr */
/* */
/* ************************************************************************** */
#include "libftprintf.h"
void ft_pfptrhex(void *p, size_t *count)
{
unsigned long temp_ptr;
unsigned long divisor;
int digit;
char *hex_base;
if (p == NULL)
{
ft_pfstr("(nil)", count);
return ;
}
temp_ptr = (unsigned long)p;
divisor = 1;
while (temp_ptr > 15)
{
temp_ptr /= 16;
divisor *= 16;
}
ft_pfstr("0x", count);
hex_base = "0123456789abcdef";
while (divisor > 0)
{
digit = (((unsigned long) p) / divisor) % 16;
ft_pfchar(hex_base[digit], count);
divisor /= 16;
}
}