Created
October 28, 2014 15:04
-
-
Save j00bar/bda6138f5dedaa59f3b5 to your computer and use it in GitHub Desktop.
Javascript decimal to base 64 converter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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