Last active
August 24, 2017 01:26
-
-
Save gaperton/674c1d2726d71403769fe5c4944b6b58 to your computer and use it in GitHub Desktop.
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
var digitsStr = | |
// 0 8 16 24 32 40 48 56 63 | |
// v v v v v v v v v | |
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+-"; | |
var digits = digitsStr.split(''), | |
codes = digits.map( x => x.charCodeAt( 0 ) ); | |
function base64id( int32 ){ | |
const a = digits[int32 & 0x3f]; | |
int32 >>>= 6; | |
const b = digits[int32 & 0x3f]; | |
int32 >>>= 6; | |
const c = digits[int32 & 0x3f]; | |
int32 >>>= 6; | |
const d = digits[int32 & 0x3f]; | |
int32 >>>= 6; | |
const e = digits[int32 & 0x3f]; | |
int32 >>>= 6; | |
const f = digits[int32 & 0x3f]; | |
int32 >>>= 6; | |
const g = digits[int32 & 0x3f]; | |
int32 >>>= 6; | |
return digits[int32 & 0x3f] + g + f + e + d + c + b + a; | |
} | |
function base64id2( int32 ){ | |
const a = codes[int32 & 0x3f]; | |
int32 >>>= 6; | |
const b = codes[int32 & 0x3f]; | |
int32 >>>= 6; | |
const c = codes[int32 & 0x3f]; | |
int32 >>>= 6; | |
const d = codes[int32 & 0x3f]; | |
int32 >>>= 6; | |
const e = codes[int32 & 0x3f]; | |
int32 >>>= 6; | |
const f = codes[int32 & 0x3f]; | |
int32 >>>= 6; | |
const g = codes[int32 & 0x3f]; | |
int32 >>>= 6; | |
return String.fromCharCode(int32 & 0x3f, g, f, e, d, c, b, a ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment