diff --git a/core/components/stringutils.cpp b/core/components/stringutils.cpp index ee473a4..12f2789 100644 --- a/core/components/stringutils.cpp +++ b/core/components/stringutils.cpp @@ -122,6 +122,26 @@ string StringUtils::bytet2Binary(uint32_t value, int bitCount, bool remoteZero) } return ret; } + +string StringUtils::bytet2BinaryHumanReadable(uint32_t value, int bitCount) { + string ret = "("; + + for (int i = 0; i < bitCount; ++i) { + uint32_t bit = value & 0x01; + value = value >> 1; + if (bit == 0) { + ret = "0" + ret; + } else { + ret = "1" + ret; + } + if ((i + 1) % 4 == 0 && i + 1 < bitCount) { + ret = " " + ret; + } + } + ret = ret + ")"; + return ret; +} + string StringUtils::bytet2BinaryBigEnd(uint32_t value, int bitCount, bool remoteZero) { string ret; for (int i = 0; i < bitCount; ++i) { diff --git a/core/components/stringutils.hpp b/core/components/stringutils.hpp index 0cc7dd7..2c67eb7 100644 --- a/core/components/stringutils.hpp +++ b/core/components/stringutils.hpp @@ -62,6 +62,7 @@ class StringUtils { * */ string bytet2Binary(uint32_t value, int bitCount, bool remoteZero = true); + string bytet2BinaryHumanReadable(uint32_t value, int bitCount); string bytet2BinaryBigEnd(uint32_t value, int bitCount, bool remoteZero = true); string escapeSequence(const string& raw_str);