38 size_t range(std::uint8_t
h, std::uint8_t l)
42 throw std::invalid_argument(fmt::format(
"Reverse ranges not supported : low={:#x} > high={:#x}", l,
h));
45 std::uint16_t
bh =
h >> 3;
46 std::uint16_t bl = l >> 3;
48 std::uint16_t rbytes =
bh - bl;
49 if ((
bh + 1) > bytes) {
50 throw std::invalid_argument(fmt::format(
"High value: out-of-range, got={:#x}, size={:#x}",
h, (bytes * 8 - 1)));
52 if ((bl + 1) > bytes) {
53 throw std::invalid_argument(fmt::format(
"Low value: out-of-range, got={:#x}, size={:#x}", l, (bytes * 8 - 1)));
56 std::uint16_t bits_in_h =
h - (8 *
bh - 1);
57 std::uint16_t bits_in_l = l - (8 * bl);
58 std::uint16_t mask_h = (1 << bits_in_h) - 1;
61 size_t r =
b[bl] >> bits_in_l;
62 if (
bh != bl) r |= (
b[
bh] & mask_h) << (rbytes * 8);
63 for (
int i = 1; i < rbytes; ++i)
64 r |=
b[bl + i] << (i * 8);