From 8ef6318a56038b5b33e44129ba5ab3a3a9bff5bb Mon Sep 17 00:00:00 2001 From: Ruakij Date: Mon, 22 Nov 2021 18:00:12 +0100 Subject: [PATCH] Added method to convert hex-char to hex-value --- helper/string-helper.hpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/helper/string-helper.hpp b/helper/string-helper.hpp index 4a89906..3bc41a6 100644 --- a/helper/string-helper.hpp +++ b/helper/string-helper.hpp @@ -17,4 +17,18 @@ std::vector split(const std::string& s, char delimiter) return tokens; } +char hex_char_to_int( char c ) { + unsigned result = -1; + if( ('0' <= c) && (c <= '9') ) { + result = c - '0'; + } + else if( ('A' <= c) && (c <= 'F') ) { + result = 10 + c - 'A'; + } + else if( ('a' <= c) && (c <= 'f') ) { + result = 10 + c - 'a'; + } + return result; +} + #endif /* F7CFE6A7_34BF_4E04_94CF_DB8374980631 */