Skip to content

Instantly share code, notes, and snippets.

@adamcameron
Created September 24, 2012 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamcameron/3776151 to your computer and use it in GitHub Desktop.
Save adamcameron/3776151 to your computer and use it in GitHub Desktop.
This is to be used in conjunction with https://gist.github.com/3776135
// testing
test.description = "A fairly easy to visually-test example";
test.number = 255;
test._baseFrom = "dec";
test._baseTo = "bin";
test._result = baseMToBaseN(test.number, test._baseFrom, test._baseTo);
writeDump(test);
test.description = "Another one";
test.number = "FFFF";
test._baseFrom = "hex";
test._baseTo = "dec";
test._result = baseMToBaseN(test.number, test._baseFrom, test._baseTo);
writeDump(test);
test.description = "Using a bespoke 'alphabet' (OCTAL in this case)";
test.number = 123;
test._baseFrom = "01234567"; // ie: octal
test._baseTo = "dec";
test._result = baseMToBaseN(test.number, test._baseFrom, test._baseTo);
writeDump(test);
test.description = "Another one using a bespoke 'alphabet' (this is URL safe)";
test.number = replace(createUuid(), "-", "", "ALL");
test._baseFrom = "hex";
test._baseTo = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-._~"; // safe for a URL
test._result = baseMToBaseN(test.number, test._baseFrom, test._baseTo);
writeDump(test);
test.description = "Converting to/from the same base";
test.number = replace(createUuid(), "-", "", "ALL");
test._baseFrom = "hex";
test._baseTo = "hex"; // safe for a URL
test._result = baseMToBaseN(test.number, test._baseFrom, test._baseTo);
writeDump(test);
test.description = "Multi-step proof it all works correctly: 1) from a GUID to BASE62";
test.number = replace(createUuid(), "-", "", "ALL");
test._baseFrom = "hex";
test._baseTo = "base62";
test._result = baseMToBaseN(test.number, test._baseFrom, test._baseTo);
writeDump(test);
test.description = "Multi-step proof it all works correctly: 2) from BASE62 to BINARY";
test.number = test._result;
test._baseFrom = "base62";
test._baseTo = "bin";
test._result = baseMToBaseN(test.number, test._baseFrom, test._baseTo);
writeDump(test);
test.description = "Multi-step proof it all works correctly: 3) from BINARY back to the original HEX";
test.number = test._result;
test._baseFrom = "bin";
test._baseTo = "hex";
test._result = baseMToBaseN(test.number, test._baseFrom, test._baseTo);
writeDump(test);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment