-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert_HEX.c
More file actions
46 lines (45 loc) · 874 Bytes
/
Copy pathconvert_HEX.c
File metadata and controls
46 lines (45 loc) · 874 Bytes
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
#include "main.h"
/**
* convert_HEX - convert to printable hexadecimal uppercase
* @a: the array to be analized
* @b: size of array
* @s: buffer
* @index: position on buffer
* Return: number of "characters" of element called
*/
int convert_HEX(int *a, int b, char *s, int *index)
{
int c = 0, y = 0, mul = 1;
int sum = 0, i, j;
int h[8] = {0};
while (c < b)
{
sum = 0;
for (i = 0; i < 4; i++)
{
if (i == 0 && c < b)
{
sum = sum + a[c];
mul = 2;
c++; }
else if (i != 0 && c < b)
{
sum = sum + (mul * a[c]);
c++;
mul = 2 * mul; }
else
break;
}
h[y] = switch_HEX(sum, h, y);
y++;
}
for (j = y - 1; j >= 0; j--)
{
if (h[j] == 'A' || h[j] == 'B' || h[j] == 'C' || h[j] == 'D'
|| h[j] == 'E' || h[j] == 'F')
set_buffer(s, h[j], index);
else
set_buffer(s, (h[j] + '0'), index);
}
return (y);
}