-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmore_custom_functions.c
54 lines (52 loc) · 986 Bytes
/
more_custom_functions.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
#include <stdio.h>
#include <unistd.h>
/**
* _itox - convert integer to hex and write
* @num: given unsigned integer
* Return: (void)
*/
int _itox(unsigned int num)
{
int length = 0;
char buffer[1024];
int i, j;
char hold;
char hexdigits[] = "0123456789abcdef";
do {
buffer[length++] = hexdigits[num % 16];
num /= 16;
} while (num > 0);
for (i = 0, j = length - 1; i < j; i++, j--)
{
hold = buffer[i];
buffer[i] = buffer[j];
buffer[j] = hold;
}
write(1, buffer, length);
return (length);
}
/**
* _itoX - conver to Hex and write
* @num: given unsigned integer
* Return: (void)
*/
int _itoX(unsigned int num)
{
int length = 0;
char buffer[1024];
int i, j;
char hold;
char hexdigits[] = "0123456789ABCDEF";
do {
buffer[length++] = hexdigits[num % 16];
num /= 16;
} while (num > 0);
for (i = 0, j = length - 1; i < j; i++, j--)
{
hold = buffer[i];
buffer[i] = buffer[j];
buffer[j] = hold;
}
write(1, buffer, length);
return (length);
}