Skip to content

Commit c606ed1

Browse files
authored
Merge pull request #49 from Zondax/add_format_function
Add format function
2 parents b2d43d0 + 40db70e commit c606ed1

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

include/zxformat.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ extern "C" {
2121

2222
#include "zxmacros.h"
2323
#include "zxerror.h"
24+
#include "stdlib.h"
2425

2526
#define IS_PRINTABLE(c) (c >= 0x20 && c <= 0x7e)
2627

@@ -301,6 +302,23 @@ __Z_INLINE uint32_t array_to_hexstr_uppercase(char *dst, uint16_t dstLen, const
301302
return (uint32_t) (count * 2);
302303
}
303304

305+
__Z_INLINE uint32_t hexstr_to_array(uint8_t *dst, uint16_t dstLen, const char *src, const uint16_t srcLen) {
306+
MEMZERO(dst, dstLen);
307+
if (srcLen % 2 != 0 || dstLen < srcLen/2) {
308+
return 0;
309+
}
310+
311+
for (size_t i = 0; i < srcLen/2; i++) {
312+
char byte_string[3];
313+
byte_string[0] = src[i*2];
314+
byte_string[1] = src[i*2 + 1];
315+
byte_string[2] = '\0';
316+
dst[i] = (uint8_t) strtol(byte_string, NULL, 16);
317+
}
318+
319+
return srcLen/2;
320+
}
321+
304322
__Z_INLINE zxerr_t to_uppercase(uint8_t *letter) {
305323
if (letter == NULL) {
306324
return zxerr_no_data;

include/zxversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717

1818
#define ZXLIB_MAJOR 16
1919
#define ZXLIB_MINOR 0
20-
#define ZXLIB_PATCH 0
20+
#define ZXLIB_PATCH 1

0 commit comments

Comments
 (0)