From 356273d71eed24c2f30bf5443455b0f37679af6c Mon Sep 17 00:00:00 2001 From: WerWolv Date: Tue, 30 Mar 2021 18:38:28 +0200 Subject: [PATCH] bug: Fix binary value in base converter being shifted by one Fixes #212 --- plugins/libimhex/include/hex/helpers/utils.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/libimhex/include/hex/helpers/utils.hpp b/plugins/libimhex/include/hex/helpers/utils.hpp index b8d999909..d2b9f1c94 100644 --- a/plugins/libimhex/include/hex/helpers/utils.hpp +++ b/plugins/libimhex/include/hex/helpers/utils.hpp @@ -195,11 +195,11 @@ namespace hex { return result; } - inline std::string toBinaryString(hex::integral auto number) { + inline std::string toBinaryString(hex::unsigned_integral auto number) { if (number == 0) return "0"; std::string result; - for (u8 bit = hex::bit_width(number); bit > 0; bit--) + for (s16 bit = hex::bit_width(number) - 1; bit >= 0; bit--) result += (number & (0b1 << bit)) == 0 ? '0' : '1'; return result;