summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrédéric Mangano2013-10-30 18:14:56 +0100
committerFrédéric Mangano2013-10-30 18:14:56 +0100
commitdafbee5b8acefdc7d004137ebccf2e7bb4b0f970 (patch)
tree2644c9652c42f748354c708a4be98e5e273bd60b
parentc69cac30a13379372c53af0b78e00c03ef053e3f (diff)
downloadlastos-dafbee5b8acefdc7d004137ebccf2e7bb4b0f970.tar.gz
lastos-dafbee5b8acefdc7d004137ebccf2e7bb4b0f970.zip
bstohex: bytestring to hexadecimal
-rw-r--r--string.c11
-rw-r--r--string.h1
2 files changed, 12 insertions, 0 deletions
diff --git a/string.c b/string.c
index f3df136..74a0657 100644
--- a/string.c
+++ b/string.c
@@ -73,6 +73,17 @@ char *u32tohex(char *dst, uint32_t n)
return dst;
}
+char *bstohex(char *dst, uint8_t *src, int sz)
+{
+ *dst = '\0';
+ for (int i = 0; i < sz; i++) {
+ u8tohex(dst + 3 * i, src[i]);
+ if (i < sz - 1)
+ dst[3 * i + 2] = ' ';
+ }
+ return dst;
+}
+
uint32_t hextou32(char *src)
{
uint32_t n = 0;
diff --git a/string.h b/string.h
index b88f2e7..6b503c5 100644
--- a/string.h
+++ b/string.h
@@ -9,5 +9,6 @@ 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);
+char *bstohex(char *dst, uint8_t *src, int sz);
uint32_t hextou32(char *src);