-
Notifications
You must be signed in to change notification settings - Fork 1
/
ft_itoa_hex.c
72 lines (65 loc) · 1.84 KB
/
ft_itoa_hex.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
66
67
68
69
70
71
72
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa_hex.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: itiievsk <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/09/17 11:48:52 by itiievsk #+# #+# */
/* Updated: 2018/09/17 11:48:54 by itiievsk ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_ssl.h"
static uint32_t swap_endian(uint32_t state)
{
uint32_t ret;
ret = ((state >> 24) & 0xff) |
((state << 8) & 0xff0000) |
((state >> 8) & 0xff00) |
((state << 24) & 0xff000000);
return (ret);
}
char *ft_itoa_hex(uint32_t state[], int size, int i, char end)
{
char *ret;
int j;
uint32_t r;
uint32_t temp;
ret = ft_strnew(size);
r = 0x10000000;
while (i < size)
{
temp = (end == 'L' ? swap_endian(state[i / 8]) : state[i / 8]);
j = 0;
while (j < 8)
{
ret[i] = HEX[temp / (r >> (4 * j))];
temp = temp % (r >> (4 * j));
j++;
i++;
}
}
return (ret);
}
char *ft_itoa_hex_512(uint64_t state[], int size, int i, char end)
{
char *ret;
int j;
uint64_t r;
uint64_t temp;
ret = ft_strnew(size);
r = 0x1000000000000000;
while (i < size)
{
temp = (end == 'L' ? 0 : state[i / 16]);
j = 0;
while (j < 16)
{
ret[i] = HEX[temp / (r >> (4 * j))];
temp = temp % (r >> (4 * j));
j++;
i++;
}
}
return (ret);
}