Skip to content

Instantly share code, notes, and snippets.

@j00bar
Created October 28, 2014 15:04
Show Gist options
  • Select an option

  • Save j00bar/bda6138f5dedaa59f3b5 to your computer and use it in GitHub Desktop.

Select an option

Save j00bar/bda6138f5dedaa59f3b5 to your computer and use it in GitHub Desktop.
Javascript decimal to base 64 converter
// this alphabet will convert an Instagram photo ID to the base 64 number used in the URLs
// however, be wary of javascript's maxint value
alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
function b64encode(i) {
if (i == 0) {
return alphabet.charAt(0);
} else {
return b64encode(Math.floor(i / 64)) + alphabet.charAt(i % 64);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment