Generic Base2/16/32/64 encoding algorithms for C++