blob: b8c337362a12b70566dc77e3d7b23233be7e5391 (
plain)
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
|
/*
* src/helpers.c
* (c) 2022 Jonas Gunz <himself@jonasgunz.de>
* License: All rights reserved.
*/
#include "helpers.h"
uint8_t hex_to_byte(char c[]) {
uint8_t ret = hex_to_halfbyte(c[0]);
ret += 16 * hex_to_halfbyte(c[1]);
return ret;
}
uint8_t hex_to_halfbyte(char c) {
uint8_t ret = 0;
if ( c >= 48 && c <= 57)
ret = c-48;
else if (c >= 65 && c <= 70)
ret = c-55;
else if (c >= 97 && c <= 102)
ret = c-87;
return ret;
}
|