16 std::string::size_type end,
17 const std::string& s) {
19 for (
auto i{begin+1}; i != end; ++i) {
24 for (std::size_t i{begin}; i != end; ++i) {
25 if (s[i] ==
'1') {val += place_val;}
31 return char(
'0' + val);
34 return char(
'a' + val-10);
39 if (s.size() == 0) {
return "";}
44 if ((s.starts_with(
"0b") or s.starts_with(
"0B")) and s.size() >=2){
45 if (s.size() == 2) {
return "";};
49 const std::string::size_type offset =
header ? 2:0;
50 const auto sz = s.size()-offset;
53 auto is_bin_char = [](
const auto& c) {
return c ==
'0' or c ==
'1';};
55 if (!std::all_of(std::cbegin(s)+offset, std::cend(s), is_bin_char)) {
56 throw std::out_of_range(
"ss contains non-binary char");
59 const auto n_ragged =
sz - 4*(
sz/4);
65 std::string::size_type start{offset};
66 std::string::size_type stop{offset+n_ragged};
70 start = offset+n_ragged;
73 if (stop > s.size()) {
return result;}
76 for (
auto i = start; i != s.size(); i += 4) {