summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrédéric Mangano2013-10-30 17:46:18 +0100
committerFrédéric Mangano2013-10-30 17:46:18 +0100
commit951b2f5346d8da51a0b0df67cec4e3ff4f017634 (patch)
tree585fb06a00067418052f4b0beafc194c71a438b6
parent47610bb5b7668b06900d3fca46ae83d5d9cf9823 (diff)
downloadlastos-951b2f5346d8da51a0b0df67cec4e3ff4f017634.tar.gz
lastos-951b2f5346d8da51a0b0df67cec4e3ff4f017634.zip
hextou32
-rw-r--r--string.c18
-rw-r--r--string.h2
2 files changed, 20 insertions, 0 deletions
diff --git a/string.c b/string.c
index 1f534a7..f3df136 100644
--- a/string.c
+++ b/string.c
@@ -72,3 +72,21 @@ char *u32tohex(char *dst, uint32_t n)
u16tohex(dst + 4, n & 0x0000FFFF);
return dst;
}
+
+uint32_t hextou32(char *src)
+{
+ uint32_t n = 0;
+ uint32_t digit;
+ for (; *src; src++) {
+ if (*src >= '0' && *src <= '9')
+ digit = *src - '0';
+ else if (*src >= 'a' && *src <= 'f')
+ digit = 10 + *src - 'a';
+ else if (*src >= 'A' && *src <= 'F')
+ digit = 10 + *src - 'A';
+ else
+ return n;
+ n = n * 16 + digit;
+ }
+ return n;
+}
diff --git a/string.h b/string.h
index 19d4849..b88f2e7 100644
--- a/string.h
+++ b/string.h
@@ -9,3 +9,5 @@ char *strcatl(char *dst, char *src, ...);
char *u8tohex(char *dst, uint8_t n);
char *u16tohex(char *dst, uint16_t n);
char *u32tohex(char *dst, uint32_t n);
+
+uint32_t hextou32(char *src);