Browse Source

update stringutils.cpp

disinfection_machine
zhaohe 2 years ago
parent
commit
ff65e55498
  1. 22
      core/components/stringutils.cpp
  2. 1
      core/components/stringutils.hpp

22
core/components/stringutils.cpp

@ -116,8 +116,26 @@ string StringUtils::bytet2Binary(uint32_t value, int bitCount, bool remoteZero)
}
}
if (remoteZero) {
while (ret[0] == '0') {
ret = ret.substr(1);
while (ret.length() > 0 && ret[0] == '0') {
ret = ret.substr(1, ret.length() - 1);
}
}
return ret;
}
string StringUtils::bytet2BinaryBigEnd(uint32_t value, int bitCount, bool remoteZero) {
string ret;
for (int i = 0; i < bitCount; ++i) {
uint32_t bit = value & 0x01;
value = value >> 1;
if (bit == 0) {
ret = ret + "0";
} else {
ret = ret + "1";
}
}
if (remoteZero) {
while (ret.length() > 0 && ret[ret.length() - 1] == '0') {
ret = ret.substr(0, ret.length() - 1);
}
}
return ret;

1
core/components/stringutils.hpp

@ -62,6 +62,7 @@ class StringUtils {
*
*/
string bytet2Binary(uint32_t value, int bitCount, bool remoteZero = true);
string bytet2BinaryBigEnd(uint32_t value, int bitCount, bool remoteZero = true);
};
} // namespace core

Loading…
Cancel
Save