Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2025-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#ifndef BITCOIN_UTIL_BYTE_UNITS_H6#define BITCOIN_UTIL_BYTE_UNITS_H8#include <util/overflow.h>10#include <limits>11#include <stdexcept>13namespace util::detail {14template <unsigned SHIFT>15consteval uint64_t ByteUnitsToBytes(unsigned long long units)16{17const auto bytes{CheckedLeftShift(units, SHIFT)};18if (!bytes || *bytes > std::numeric_limits<uint64_t>::max()) {19throw std::overflow_error("Too large");20}21return *bytes;22}23} // namespace util::detail25/// Conversion of MiB to bytes.26consteval uint64_t operator""_MiB(unsigned long long mebibytes)27{28return util::detail::ByteUnitsToBytes<20>(mebibytes);29}31/// Conversion of GiB to bytes.32consteval uint64_t operator""_GiB(unsigned long long gibibytes)33{34return util::detail::ByteUnitsToBytes<30>(gibibytes);35}37#endif // BITCOIN_UTIL_BYTE_UNITS_H