<h1>Base99 Converter</h1>
<textarea class='input-box'></textarea>
<div class='action-bar'>
<button class='dec_b99-action-btn'>Convert Decimal to Base99</button>
<button class='b99_dec-action-btn'>Convert Base99 to Decimal</button>
</div>
<textarea class='output-box' disabled></textarea>
<br />
<h3>Define the <i>base99 conversion system.</i></h3>
<p>A <i>base99 conversion system</i> would use 99 distinct symbols to represent numbers. For example, you could use the digits 0-9 and the letters A-Z (lowercase and uppercase) to represent the first 62 symbols. You would then need to choose an additional 37 symbols to represent the remaining values.</p>
<h3>Who created it and why?</h3>
<p><a href="mailto:[email protected]">Abhishek Kumar</a> have created it out of curiosity to convert the date into few characters that could be used as short timestamp.</p>
// base99Characters is a string containing the characters used to represent the digits in the base99 system.
const base99Characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#$%^&*()_+-=[]{}|;:,.<>/?`~';
// decimalToBase99 converts a decimal number to its base99 equivalent.
function decimalToBase99(decimalNumber) {
let result = '';
while (decimalNumber > 0) {
let remainder = decimalNumber % 99;
result = base99Characters[remainder] + result;
decimalNumber = Math.floor(decimalNumber / 99);
}
return result;
}
// base99ToDecimal converts a base99 string to its decimal equivalent.
function base99ToDecimal(base99String) {
let result = 0;
for (let i = 0; i < base99String.length; i++) {
let digitValue = base99Characters.indexOf(base99String[i]);
result = result * 99 + digitValue;
}
return result;
}
function main() {
let inputBox = document.querySelector('.input-box');
let outputBox = document.querySelector('.output-box');
let dec_b99_actionBtn = document.querySelector('.dec_b99-action-btn');
dec_b99_actionBtn.addEventListener('click', evt => {
let iVal = inputBox.value;
outputBox.value = decimalToBase99(iVal);
});
let b99_dec_actionBtn = document.querySelector('.b99_dec-action-btn');
b99_dec_actionBtn.addEventListener('click', evt => {
let iVal = inputBox.value;
outputBox.value = base99ToDecimal(iVal);
});
}
main();
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.