17inline namespace cpp20 {
28 return (N == 0) ? 0 : (N % 10) + (2 *
binary_func(N/10));
38consteval uint32_t
binary(uint64_t
const N)
59 {.expected = 1, .got =
binary(1)},
60 {.expected = 3, .got =
binary(11)},
61 {.expected = 5, .got =
binary(101)},
62 {.expected = 7, .got =
binary(111)},
63 {.expected = 9, .got =
binary(1001)},
72 for (
auto const& vals :
run) {
73 printf(
"Should be %u: %u\n", vals.expected, vals.got);
constexpr struct anonymous_namespace{chapter-1.cpp}::@0 run[]
the container for test input and output.
constexpr uint32_t binary_func(uint64_t const N)
A runtime binary to decimal number translation.
Prepend higher bits to lowest bit.