mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
* added StrHelper::fromHex()
This commit is contained in:
parent
1520f4d28e
commit
b31d3e7b5f
2 changed files with 21 additions and 0 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue