| 37 | namespace SURELOG { |
| 38 | |
| 39 | std::string NumUtils::hexToBin(std::string_view s) { |
| 40 | std::string out; |
| 41 | out.reserve(s.length() * 4); |
| 42 | for (auto i : s) { |
| 43 | uint8_t n; |
| 44 | if ((i <= '9') && (i >= '0')) |
| 45 | n = i - '0'; |
| 46 | else |
| 47 | n = 10 + i - 'A'; |
| 48 | for (int8_t j = 3; j >= 0; --j) out.push_back((n & (1 << j)) ? '1' : '0'); |
| 49 | } |
| 50 | size_t pos = out.find('1'); |
| 51 | if (pos == std::string::npos) |
| 52 | out.clear(); |
| 53 | else |
| 54 | out = out.substr(pos); |
| 55 | return out; |
| 56 | } |
| 57 | |
| 58 | std::string NumUtils::binToHex(std::string_view s) { |
| 59 | std::string out; |