From 4e96a41b4ee6bbc920b7c5a5ec555d6d14e65b18 Mon Sep 17 00:00:00 2001 From: gameboyprinter Date: Thu, 5 Jul 2018 12:26:15 -0500 Subject: better int to hex --- hex_functions.cpp | 34 +++++++++------------------------- 1 file changed, 9 insertions(+), 25 deletions(-) (limited to 'hex_functions.cpp') diff --git a/hex_functions.cpp b/hex_functions.cpp index 9db2b0a7..c503af6b 100644 --- a/hex_functions.cpp +++ b/hex_functions.cpp @@ -4,6 +4,9 @@ namespace omni { + // This might be unused but I don't care to search the entire source code + // So it will remain here (lol) + // The actual int to hex conversion is now done properly char halfword_to_hex_char(unsigned int input) { if (input > 127) @@ -53,31 +56,12 @@ namespace omni if (input > 255) return "FF"; - std::bitset<8> whole_byte(input); - //240 represents 11110000, our needed bitmask - uint8_t left_mask_int = 240; - std::bitset<8> left_mask(left_mask_int); - std::bitset<8> left_halfword((whole_byte & left_mask) >> 4); - //likewise, 15 represents 00001111 - uint8_t right_mask_int = 15; - std::bitset<8> right_mask(right_mask_int); - std::bitset<8> right_halfword((whole_byte & right_mask)); + std::stringstream stream; + stream << std::setfill ('0') << std::setw(sizeof(char)*2) + << std::hex << your_int; + std::string result(stream.str()); + std::transform(str.begin(), str.end(), str.begin(), ::toupper); - unsigned int left = left_halfword.to_ulong(); - unsigned int right = right_halfword.to_ulong(); - - //std::cout << "now have have " << left << " and " << right << '\n'; - - char a = halfword_to_hex_char(left); - char b = halfword_to_hex_char(right); - - std::string left_string(1, a); - std::string right_string(1, b); - - std::string final_byte = left_string + right_string; - - //std::string final_byte = halfword_to_hex_char(left) + "" + halfword_to_hex_char(right); - - return final_byte; + return result; } } //namespace omni -- cgit From bb0b767ba40d189b97ffe371ab063c5380609b0c Mon Sep 17 00:00:00 2001 From: Denton Date: Thu, 5 Jul 2018 12:47:36 -0500 Subject: pretend you didnt see this --- hex_functions.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'hex_functions.cpp') diff --git a/hex_functions.cpp b/hex_functions.cpp index c503af6b..e07a7b08 100644 --- a/hex_functions.cpp +++ b/hex_functions.cpp @@ -58,7 +58,7 @@ namespace omni std::stringstream stream; stream << std::setfill ('0') << std::setw(sizeof(char)*2) - << std::hex << your_int; + << std::hex << input; std::string result(stream.str()); std::transform(str.begin(), str.end(), str.begin(), ::toupper); -- cgit From e36dae20b7d1baba912c55ec55b82a380c4973da Mon Sep 17 00:00:00 2001 From: oldmud0 Date: Thu, 5 Jul 2018 21:26:05 -0500 Subject: Fix hex_functions compile errors --- hex_functions.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'hex_functions.cpp') diff --git a/hex_functions.cpp b/hex_functions.cpp index e07a7b08..683097ee 100644 --- a/hex_functions.cpp +++ b/hex_functions.cpp @@ -57,10 +57,10 @@ namespace omni return "FF"; std::stringstream stream; - stream << std::setfill ('0') << std::setw(sizeof(char)*2) + stream << std::setfill('0') << std::setw(sizeof(char)*2) << std::hex << input; std::string result(stream.str()); - std::transform(str.begin(), str.end(), str.begin(), ::toupper); + std::transform(result.begin(), result.end(), result.begin(), ::toupper); return result; } -- cgit