void RegisterValue::fromByteArray(const QByteArray &ba, RegisterFormat format) { known = !ba.isEmpty(); v.u64[1] = v.u64[0] = 0; const int n = ba.size(); int pos = 0; if (ba.startsWith("0x")) pos += 2; bool negative = pos < n && ba.at(pos) == '-'; if (negative) ++pos; while (pos < n) { uint c = ba.at(pos); if (format != CharacterFormat) { c = decodeHexChar(c); if (c == uint(-1)) break; } shiftOneDigit(c, format); ++pos; } if (negative) { v.u64[1] = ~v.u64[1]; v.u64[0] = ~v.u64[0]; ++v.u64[0]; if (v.u64[0] == 0) ++v.u64[1]; } }
void RegisterValue::fromString(const QString &str, RegisterFormat format) { known = !str.isEmpty(); v.u64[1] = v.u64[0] = 0; const int n = str.size(); int pos = 0; if (str.startsWith("0x")) pos += 2; bool negative = pos < n && str.at(pos) == '-'; if (negative) ++pos; while (pos < n) { uint c = str.at(pos).unicode(); if (format != CharacterFormat) { c = decodeHexChar(c); if (c == uint(-1)) break; } shiftOneDigit(c, format); ++pos; } if (negative) { v.u64[1] = ~v.u64[1]; v.u64[0] = ~v.u64[0]; ++v.u64[0]; if (v.u64[0] == 0) ++v.u64[1]; } }
void RegisterValue::operator=(const QByteArray &ba) { uint shift = 0; int j = 0; v.u64[1] = v.u64[0] = 0; for (int i = ba.size(); --i >= 0 && j < 16; ++j) { quint64 d = decodeHexChar(ba.at(i)); if (d == uint(-1)) return; v.u64[0] |= (d << shift); shift += 4; } j = 0; shift = 0; for (int i = ba.size() - 16; --i >= 0 && j < 16; ++j) { quint64 d = decodeHexChar(ba.at(i)); if (d == uint(-1)) return; v.u64[1] |= (d << shift); shift += 4; } }