File: base57.hpp

package info (click to toggle)
higan 106-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 9,640 kB
  • sloc: cpp: 108,736; ansic: 809; makefile: 22; sh: 7
file content (19 lines) | stat: -rw-r--r-- 426 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#pragma once

#include <nall/arithmetic.hpp>

namespace nall { namespace Encode {

template<typename T> inline auto Base57(T value) -> string {
  static const char lookup[] = "23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
  static const uint size = ceil(sizeof(T) * 8 / log2(57));

  string result;
  for(auto n : range(size)) {
    result.append(lookup[value % 57]);
    value /= 57;
  }
  return result;
}

}}