-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathparse_x_X.c
66 lines (57 loc) · 1.21 KB
/
parse_x_X.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
#include "main.h"
/**
* parse_hex - substitute %x by unsigned int argument number
* @buff_dest: string to change
* @arg: va_list arg to change
* @buff_count: index of buffer where the o of %x is
* Return: New index
*/
int parse_hex(char *buff_dest, va_list arg, int buff_count)
{
unsigned int number = va_arg(arg, unsigned int);
unsigned int tmp = number;
int hex = 1;
while (tmp > 15)
{
hex *= 16;
tmp /= 16;
}
tmp = number;
while (hex > 0)
{
buff_dest[buff_count] = (tmp / hex < 9) ?
(tmp / hex + '0') : ('a' + tmp / hex - 10);
tmp %= hex;
hex /= 16;
buff_count++;
}
return (buff_count);
}
/**
* parse_X - substitute %X by unsigned int argument number
* @buff_dest: string to change
* @arg: va_list arg to change
* @buff_count: index of buffer where the o of %X is
* Return: New index
*/
int parse_X(char *buff_dest, va_list arg, int buff_count)
{
unsigned int number = va_arg(arg, unsigned int);
unsigned int tmp = number;
int hex = 1;
while (tmp > 15)
{
hex *= 16;
tmp /= 16;
}
tmp = number;
while (hex > 0)
{
buff_dest[buff_count] = (tmp / hex < 9) ?
(tmp / hex + '0') : ('A' + tmp / hex - 10);
tmp %= hex;
hex /= 16;
buff_count++;
}
return (buff_count);
}