我正在尝试创建一个函数来将十进制转换为平衡的 Heptavintimal (0123456789ABCDEFGHKMNPRTVXZ),其中 0 代表 -13,D:0 和 Z 13
我已经尝试过了,但有些情况无法正常工作:
static const std::string HEPT_CHARS = "0123456789ABCDEFGHKMNPRTVXZ";
std::string heptEnc(int value){
std::string result = "";
do {
int pos = value % 27;
result = std::string(HEPT_CHARS[(pos + 13)%27] + result);
value = value / 27;
} while (value != 0);
return result;
}
这是我在这个例子中得到的 -14、-15、14、15 不起作用
call(x) - expect: result
heptEnc(-9841) - 000: 000
heptEnc(-15) - CX:
heptEnc(-14) - CZ:
heptEnc(-13) - 0: 0
heptEnc(-1) - C: C
heptEnc(0) - D: D
heptEnc(1) - E: E
heptEnc(13) - Z: Z
heptEnc(14) - E0: 0
heptEnc(15) - E1: 1
heptEnc(9841) - ZZZ: ZZZ