feat: add hex

This commit is contained in:
2026-01-29 23:22:17 +01:00
parent 110d1df50d
commit f49802a1a6
4 changed files with 179 additions and 0 deletions

58
include/cpputils/hex.h Normal file
View File

@@ -0,0 +1,58 @@
#pragma once
#include <string>
namespace cpputils {
namespace hex {
std::string toHex(std::string const& input);
std::string fromHex(std::string const& input);
constexpr int hexVal(char c) {
switch (c) {
case '0':
return 0;
case '1':
return 1;
case '2':
return 2;
case '3':
return 3;
case '4':
return 4;
case '5':
return 5;
case '6':
return 6;
case '7':
return 7;
case '8':
return 8;
case '9':
return 9;
case 'a':
case 'A':
return 10;
case 'b':
case 'B':
return 11;
case 'c':
case 'C':
return 12;
case 'd':
case 'D':
return 13;
case 'e':
case 'E':
return 14;
case 'f':
case 'F':
return 15;
default:
return -1;
}
}
} // namespace hex
} // namespace cpputils