mirror of
https://github.com/momo5502/emulator.git
synced 2026-01-18 19:23:56 +00:00
Small cleanup and utils
This commit is contained in:
@@ -79,6 +79,29 @@ namespace utils::string
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename Integer>
|
||||
requires(std::is_integral_v<Integer>)
|
||||
std::string to_hex_number(const Integer& i, const bool uppercase = false)
|
||||
{
|
||||
std::string res{};
|
||||
res.reserve(sizeof(i) * 2);
|
||||
|
||||
const std::span data{reinterpret_cast<const std::byte*>(&i), sizeof(i)};
|
||||
|
||||
for (const auto value : data)
|
||||
{
|
||||
const auto [high, low] = to_hex(value, uppercase);
|
||||
res.insert(res.begin(), {high, low});
|
||||
}
|
||||
|
||||
while (res.size() > 1 && res.front() == '0')
|
||||
{
|
||||
res.erase(res.begin());
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
template <typename Integer>
|
||||
requires(std::is_integral_v<Integer>)
|
||||
std::string to_hex_string(const Integer& i, const bool uppercase = false)
|
||||
|
||||
Reference in New Issue
Block a user