-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlowhex.c
More file actions
51 lines (46 loc) · 1.34 KB
/
lowhex.c
File metadata and controls
51 lines (46 loc) · 1.34 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
/* ************************************************************************** */
/* */
/* :::::::: */
/* lowhex.c :+: :+: */
/* +:+ */
/* By: candace <candace@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2021/12/02 08:26:56 by candace #+# #+# */
/* Updated: 2021/12/02 18:44:21 by cstaats ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libftprintf.h"
#include <limits.h>
int lowhex(unsigned long n, char *str, int fd)
{
int index;
if (n == 0)
{
ft_putstr_fd("0", fd);
return (1);
}
if (n < 0)
n = INT_MAX;
if (n / 16 > 0)
{
lowhex(n / 16, str, fd);
}
index = n % 16;
ft_putchar_fd(str[index], fd);
return (hexlen(n));
}
int hexlen(unsigned long a)
{
int cnt;
cnt = 0;
if (a == 0)
return (1);
if (a < 0)
cnt++;
while (a != 0)
{
a = (a / 16);
cnt++;
}
return (cnt);
}