|
|
@@ -25,3 +25,20 @@ uint8_t from_hex(uint8_t ch) |
|
|
|
const uint8_t hex[16]={'0','1','2','3','4','5','6','7', |
|
|
|
'8','9','a','b','c','d','e','f'}; |
|
|
|
|
|
|
|
/* Convert 4 ASCII hex digits into a 16-bit unsigned number. |
|
|
|
Returns the number, or -1 if there's an error */ |
|
|
|
int32_t hex_to_u16(char x[4]) |
|
|
|
{ |
|
|
|
uint16_t v = 0; |
|
|
|
uint8_t t; |
|
|
|
int i; |
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) { |
|
|
|
t = from_hex(x[i]); |
|
|
|
if (t >= 16) |
|
|
|
return -1; |
|
|
|
v = (v << 4) | t; |
|
|
|
} |
|
|
|
return v; |
|
|
|
} |
|
|
|
|