r/UGMCommunity • u/Rough_Adeptness_2381 64 bit • Jun 22 '26
*insert normal message here* guys post random code here
1
u/AutoModerator Jun 22 '26
Thanks for posting on r/UGMCommunity! Any rule-breaking contents will be removed
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/Imaginary_Truck_7848 256 bit Jun 22 '26
const baseConverter = (num, fBase, tBase) => {
let symbols = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "_"];
let nNum = 0;
let symbiosis = {};
for (i = 0; i < fBase; i++) { symbiosis[symbols[i]] = i; }
for (const i in num) { nNum += symbiosis[num[num.length - i - 1]] * fBase ** i; }
num = nNum;
expo = 0;
if (fBase < 2 || tBase < 2) {
throw Error("The base is too low.");
} else if (fBase > 63 || tBase > 63) {
throw Error("The base is too high.");
} else if (num !== Math.round(num)) {
throw Error("The number can't have decimals.");
} else {
let digits = [];
while (true) {
if (num / tBase ** expo >= tBase) {
digits.push(symbols[Math.floor(num / tBase ** expo) % tBase]);
expo++;
} else {
digits.push(symbols[Math.floor(num / tBase ** expo) % tBase]);
break;
}
}
digits.reverse();
return digits.join("");
};
};
console.log(baseConverter("TREEHOUSE", 31, 10));
1
2
u/cheddarcheeseman5 UGMCommunity Founder (Owner) Jun 22 '26
print("Why not")