* added StrHelper::fromHex()

This commit is contained in:
Scott Powell 2025-11-09 16:17:49 +11:00
parent 1520f4d28e
commit b31d3e7b5f
2 changed files with 21 additions and 0 deletions

View file

@ -139,3 +139,23 @@ const char* StrHelper::ftoa(float f) {
}
return tmp;
}
uint32_t StrHelper::fromHex(const char* src) {
uint32_t n = 0;
while (*src) {
if (*src >= '0' && *src <= '9') {
n <<= 4;
n |= (*src - '0');
} else if (*src >= 'A' && *src <= 'F') {
n <<= 4;
n |= (*src - 'A' + 10);
} else if (*src >= 'a' && *src <= 'f') {
n <<= 4;
n |= (*src - 'a' + 10);
} else {
break; // non-hex char encountered, stop parsing
}
src++;
}
return n;
}

View file

@ -13,4 +13,5 @@ public:
static void strzcpy(char* dest, const char* src, size_t buf_sz); // pads with trailing nulls
static const char* ftoa(float f);
static bool isBlank(const char* str);
static uint32_t fromHex(const char* src);
};