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) 2009-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#include <crypto/hex_base.h>7#include <array>8#include <cassert>9#include <cstring>10#include <string>12namespace {14using ByteAsHex = std::array<char, 2>;16constexpr std::array<ByteAsHex, 256> CreateByteToHexMap()17{18constexpr char hexmap[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};20std::array<ByteAsHex, 256> byte_to_hex{};21for (size_t i = 0; i < byte_to_hex.size(); ++i) {22byte_to_hex[i][0] = hexmap[i >> 4];23byte_to_hex[i][1] = hexmap[i & 15];24}25return byte_to_hex;26}28} // namespace30std::string HexStr(const std::span<const uint8_t> s)31{32std::string rv(s.size() * 2, '\0');33static constexpr auto byte_to_hex = CreateByteToHexMap();34static_assert(sizeof(byte_to_hex) == 512);36char* it = rv.data();37for (uint8_t v : s) {38std::memcpy(it, byte_to_hex[v].data(), 2);39it += 2;40}42assert(it == rv.data() + rv.size());43return rv;44}46const signed char p_util_hexdigit[256] =47{ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,48-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,49-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,500,1,2,3,4,5,6,7,8,9,-1,-1,-1,-1,-1,-1,51-1,0xa,0xb,0xc,0xd,0xe,0xf,-1,-1,-1,-1,-1,-1,-1,-1,-1,52-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,53-1,0xa,0xb,0xc,0xd,0xe,0xf,-1,-1,-1,-1,-1,-1,-1,-1,-1,54-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,55-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,56-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,57-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,58-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,59-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,60-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,61-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, };64signed char HexDigit(char c)65{66return p_util_hexdigit[(unsigned char)c];67}