Browse Source

添加 bytet2BinaryHumanReadable

disinfection_machine
zhaohe 2 years ago
parent
commit
b50613ad32
  1. 20
      core/components/stringutils.cpp
  2. 1
      core/components/stringutils.hpp

20
core/components/stringutils.cpp

@ -122,6 +122,26 @@ string StringUtils::bytet2Binary(uint32_t value, int bitCount, bool remoteZero)
} }
return ret; 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 StringUtils::bytet2BinaryBigEnd(uint32_t value, int bitCount, bool remoteZero) {
string ret; string ret;
for (int i = 0; i < bitCount; ++i) { for (int i = 0; i < bitCount; ++i) {

1
core/components/stringutils.hpp

@ -62,6 +62,7 @@ class StringUtils {
* *
*/ */
string bytet2Binary(uint32_t value, int bitCount, bool remoteZero = true); 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 bytet2BinaryBigEnd(uint32_t value, int bitCount, bool remoteZero = true);
string escapeSequence(const string& raw_str); string escapeSequence(const string& raw_str);

Loading…
Cancel
Save