-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_hex.c
More file actions
37 lines (34 loc) · 1.2 KB
/
ft_hex.c
File metadata and controls
37 lines (34 loc) · 1.2 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_hex.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bschwitz <marvin@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/24 15:03:42 by bschwitz #+# #+# */
/* Updated: 2021/12/07 17:11:38 by bschwitz ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
#include <unistd.h>
int ft_hex(unsigned int nbr, char *base)
{
int i;
int j;
char hexa[100];
j = 0;
i = 0;
if (nbr == 0)
i = i + write(1, base, 1);
while (nbr != 0)
{
hexa[j++] = base[nbr % 16];
nbr = nbr / 16;
}
while (j != 0)
{
i = i + write(1, &hexa[j - 1], 1);
j--;
}
return (i);
}