using System;
using System.Linq;
public class Test
{
public static void Main()
{
Console.WriteLine(BaseConvert("8418CFEE73FA22E6AB0760C73A496497C6C347DA88A9F63B95FE1E1D6A350AA1D7D3A9EE870795AECC3C109AA8B4A78C", 16, 36));
}
public static string BaseConvert(string number, int fromBase, int toBase)
{
var digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var length = number.Length;
var result = string.Empty;
var nibbles = number.Select(c => digits.IndexOf(c)).ToList();
int newlen;
do {
var value = 0;
newlen = 0;
for (var i = 0; i < length; ++i) {
value = value * fromBase + nibbles[i];
if (value >= toBase) {
if (newlen == nibbles.Count) {
nibbles.Add(0);
}
nibbles[newlen++] = value / toBase;
value %= toBase;
}
else if (newlen > 0) {
if (newlen == nibbles.Count) {
nibbles.Add(0);
}
nibbles[newlen++] = 0;
}
}
length = newlen;
result = digits[value] + result; //
}
while (newlen != 0);
return result;
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uTGlucTsKCnB1YmxpYyBjbGFzcyBUZXN0CnsKCXB1YmxpYyBzdGF0aWMgdm9pZCBNYWluKCkKCXsKCQlDb25zb2xlLldyaXRlTGluZShCYXNlQ29udmVydCgiODQxOENGRUU3M0ZBMjJFNkFCMDc2MEM3M0E0OTY0OTdDNkMzNDdEQTg4QTlGNjNCOTVGRTFFMUQ2QTM1MEFBMUQ3RDNBOUVFODcwNzk1QUVDQzNDMTA5QUE4QjRBNzhDIiwgMTYsIDM2KSk7Cgl9CglwdWJsaWMgc3RhdGljIHN0cmluZyBCYXNlQ29udmVydChzdHJpbmcgbnVtYmVyLCBpbnQgZnJvbUJhc2UsIGludCB0b0Jhc2UpCgl7CgkgICAgdmFyIGRpZ2l0cyA9ICIwMTIzNDU2Nzg5QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVoiOwoJICAgIHZhciBsZW5ndGggPSBudW1iZXIuTGVuZ3RoOwoJICAgIHZhciByZXN1bHQgPSBzdHJpbmcuRW1wdHk7CgkKCSAgICB2YXIgbmliYmxlcyA9IG51bWJlci5TZWxlY3QoYyA9PiBkaWdpdHMuSW5kZXhPZihjKSkuVG9MaXN0KCk7CgkgICAgaW50IG5ld2xlbjsKCSAgICBkbyB7CgkgICAgICAgIHZhciB2YWx1ZSA9IDA7CgkgICAgICAgIG5ld2xlbiA9IDA7CgkKCSAgICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCBsZW5ndGg7ICsraSkgewoJICAgICAgICAgICAgdmFsdWUgPSB2YWx1ZSAqIGZyb21CYXNlICsgbmliYmxlc1tpXTsKCSAgICAgICAgICAgIGlmICh2YWx1ZSA+PSB0b0Jhc2UpIHsKCSAgICAgICAgICAgICAgICBpZiAobmV3bGVuID09IG5pYmJsZXMuQ291bnQpIHsKCSAgICAgICAgICAgICAgICAgICAgbmliYmxlcy5BZGQoMCk7CgkgICAgICAgICAgICAgICAgfQoJICAgICAgICAgICAgICAgIG5pYmJsZXNbbmV3bGVuKytdID0gdmFsdWUgLyB0b0Jhc2U7CgkgICAgICAgICAgICAgICAgdmFsdWUgJT0gdG9CYXNlOwoJICAgICAgICAgICAgfQoJICAgICAgICAgICAgZWxzZSBpZiAobmV3bGVuID4gMCkgewoJICAgICAgICAgICAgICAgIGlmIChuZXdsZW4gPT0gbmliYmxlcy5Db3VudCkgewoJICAgICAgICAgICAgICAgICAgICBuaWJibGVzLkFkZCgwKTsKCSAgICAgICAgICAgICAgICB9CgkgICAgICAgICAgICAgICAgbmliYmxlc1tuZXdsZW4rK10gPSAwOwoJICAgICAgICAgICAgfQoJICAgICAgICB9CgkgICAgICAgIGxlbmd0aCA9IG5ld2xlbjsKCSAgICAgICAgcmVzdWx0ID0gZGlnaXRzW3ZhbHVlXSArIHJlc3VsdDsgLy8KCSAgICB9CgkgICAgd2hpbGUgKG5ld2xlbiAhPSAwKTsKCQoJICAgIHJldHVybiByZXN1bHQ7Cgl9Cn0=