-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitoa_base.c
60 lines (55 loc) · 1.56 KB
/
itoa_base.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* itoa_base.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nahmed-m <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/01/24 19:30:58 by nahmed-m #+# #+# */
/* Updated: 2016/01/25 16:45:34 by nahmed-m ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void ft_itoa_base(unsigned long value, unsigned long base, char up)
{
unsigned long i;
unsigned long j;
char *hex;
char *hex_low;
hex = "0123456789ABCDEF";
hex_low = "0123456789abcdef";
j = 0;
i = 1;
while (value / i > base - 1)
i *= base;
while (i != 0)
{
if (up == 0)
ft_putchar(hex[value / i]);
else
ft_putchar(hex_low[value / i]);
value %= i;
i /= base;
j++;
}
}
int ft_itoa_count(unsigned long value, unsigned long base, t_var *e)
{
unsigned long i;
unsigned long j;
int c;
c = 0;
j = 0;
i = 1;
while (value / i > base - 1)
i *= base;
while (i != 0)
{
c++;
value %= i;
i /= base;
j++;
e->ret++;
}
return (c);
}