summaryrefslogtreecommitdiffstats
path: root/src/common/hex_util.cpp
diff options
context:
space:
mode:
authorZach Hilman <zachhilman@gmail.com>2018-10-01 00:13:02 +0200
committerZach Hilman <zachhilman@gmail.com>2018-10-04 17:32:04 +0200
commitf62227aa95f96901b75670d3914971593f65f119 (patch)
tree8c667ca88014a0764412993f68fd5b11c93036e8 /src/common/hex_util.cpp
parentMerge pull request #1415 from DarkLordZach/ips (diff)
downloadyuzu-f62227aa95f96901b75670d3914971593f65f119.tar
yuzu-f62227aa95f96901b75670d3914971593f65f119.tar.gz
yuzu-f62227aa95f96901b75670d3914971593f65f119.tar.bz2
yuzu-f62227aa95f96901b75670d3914971593f65f119.tar.lz
yuzu-f62227aa95f96901b75670d3914971593f65f119.tar.xz
yuzu-f62227aa95f96901b75670d3914971593f65f119.tar.zst
yuzu-f62227aa95f96901b75670d3914971593f65f119.zip
Diffstat (limited to '')
-rw-r--r--src/common/hex_util.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/common/hex_util.cpp b/src/common/hex_util.cpp
index 589ae5cbf..e516e5bbd 100644
--- a/src/common/hex_util.cpp
+++ b/src/common/hex_util.cpp
@@ -18,6 +18,25 @@ u8 ToHexNibble(char c1) {
return 0;
}
+std::vector<u8> HexStringToVector(std::string_view str, bool little_endian) {
+ std::vector<u8> out(str.size() / 2);
+ if (little_endian) {
+ for (std::size_t i = str.size() - 2; i <= str.size(); i -= 2)
+ out[i / 2] = (ToHexNibble(str[i]) << 4) | ToHexNibble(str[i + 1]);
+ } else {
+ for (std::size_t i = 0; i < str.size(); i += 2)
+ out[i / 2] = (ToHexNibble(str[i]) << 4) | ToHexNibble(str[i + 1]);
+ }
+ return out;
+}
+
+std::string HexVectorToString(std::vector<u8> vector, bool upper) {
+ std::string out;
+ for (u8 c : vector)
+ out += fmt::format(upper ? "{:02X}" : "{:02x}", c);
+ return out;
+}
+
std::array<u8, 16> operator""_array16(const char* str, std::size_t len) {
if (len != 32) {
LOG_ERROR(Common,