MCPcopy Create free account
hub / github.com/chipsalliance/Surelog / hexToBin

Method hexToBin

src/Utils/NumUtils.cpp:39–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37namespace SURELOG {
38
39std::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
58std::string NumUtils::binToHex(std::string_view s) {
59 std::string out;

Callers

nothing calls this directly

Calls 1

clearMethod · 0.80

Tested by

no test coverage detected