| 1071 | // ------------------------------------------------ |
| 1072 | |
| 1073 | std::string Int::GetBaseN(int n,char *charset) { |
| 1074 | |
| 1075 | std::string ret; |
| 1076 | |
| 1077 | Int N(this); |
| 1078 | int isNegative = N.IsNegative(); |
| 1079 | if (isNegative) N.Neg(); |
| 1080 | |
| 1081 | // TODO: compute max digit |
| 1082 | unsigned char digits[1024]; |
| 1083 | memset(digits, 0, sizeof(digits)); |
| 1084 | |
| 1085 | int digitslen = 1; |
| 1086 | for (int i = 0; i < NB64BLOCK * 8; i++) { |
| 1087 | unsigned int carry = N.GetByte(NB64BLOCK*8 - i - 1); |
| 1088 | for (int j = 0; j < digitslen; j++) { |
| 1089 | carry += (unsigned int)(digits[j]) << 8; |
| 1090 | digits[j] = (unsigned char)(carry % n); |
| 1091 | carry /= n; |
| 1092 | } |
| 1093 | while (carry > 0) { |
| 1094 | digits[digitslen++] = (unsigned char)(carry % n); |
| 1095 | carry /= n; |
| 1096 | } |
| 1097 | } |
| 1098 | |
| 1099 | // reverse |
| 1100 | if (isNegative) |
| 1101 | ret.push_back('-'); |
| 1102 | |
| 1103 | for (int i = 0; i < digitslen; i++) |
| 1104 | ret.push_back(charset[digits[digitslen - 1 - i]]); |
| 1105 | |
| 1106 | if (ret.length() == 0) |
| 1107 | ret.push_back('0'); |
| 1108 | |
| 1109 | return ret; |
| 1110 | |
| 1111 | } |
| 1112 | |
| 1113 | // ------------------------------------------------ |
| 1114 |
nothing calls this directly
no test coverage detected