base

name

base, base_upper - convert decimimal to base<n>

synopsis

#include<fast_io.h>
using namespace fast_io::mnp;

base<n>(ref);
base_upper<n>(ref);

// n is integer and 2 <= n <=36
// ref = integer || pointer_v || contiguous_iterator

description

Both base() and base_upper() work with print family as parameter of print() and specify the non-type-parameter, which is integer .

example

#include<fast_io.h>
#include<fast_io_device.h>

void f() {};
int main() {
    using namespace fast_io::mnp;
    constexpr int i{123157};
    std::string str{concat(
        "hex\tdec\toct\tbin\tbase<36>\n",
        hex(i),"\t",dec(i),"\t",oct(i),"\t",bin(i),"\t",base<36>(i),"\n",
        "hex_upper\tdec\toct\tbin\tbase_upper<36>\n",
        hex_upper(i),"\t",dec(i),"\t",oct(i),"\t",bin(i),"\t",base_upper<36>(i),"\n")};
    print(auto_indent(str));
    print("\n\n");
    // dec oct bin
    // they hasn't suffix
    // hex_upper hex dec oct bin
    // the readability of them is poor,
    // recommend to use base<2> base<8> base<16> base_upper<16>
    println("ubase:               ",ubase<36>(i));
    println("ubase_upper:         ",ubase_upper<36>(i));
    print("\n\n");

    std::vector vec{1,2,4,36,25};
    auto vec_it = vec.begin();
    std::array arr{1,2,4,36,25};
    auto arr_it = arr.begin();
    int const* p{&i};

    str = fast_io::concat("for int poiter","\t",base<8>(p),"\n"
           "for function poiter","\t",base<8>(f),"\n"
           "for vector iterator","\t",base<8>(vec_it),"\n"
           "for array iterator","\t",base<8>(arr_it),"\n");
    println(auto_indent(str));
}

see also

print

concat