-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_printh.c
72 lines (65 loc) · 1.52 KB
/
ft_printh.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printh.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bhagenlo <[email protected]. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/13 15:47:14 by bhagenlo #+# #+# */
/* Updated: 2022/05/02 15:15:24 by bhagenlo ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_numlen(long long n, int base)
{
int numlen;
numlen = 0;
if (n == 0)
return (1);
if (base == 10)
{
if (n < 0)
{
numlen++;
n = -n;
}
}
while (n)
{
n /= base;
numlen++;
}
return (numlen);
}
int ft_plen(uintptr_t n)
{
int numlen;
if (n == 0)
return (1);
numlen = 0;
while (n)
{
n /= 16;
numlen++;
}
return (numlen);
}
void ft_puthex(uintptr_t num, int to_upper)
{
char c;
c = 'a';
if (to_upper)
c = 'A';
if (num >= 16)
{
ft_puthex(num / 16, to_upper);
ft_puthex(num % 16, to_upper);
}
else
{
if (num <= 9)
ft_printc(num + '0');
else
ft_printc(num - 10 + c);
}
}