Created
September 5, 2017 00:23
-
-
Save Caaz/dad28c14ed3f3f9e465aa6af0423e579 to your computer and use it in GitHub Desktop.
Shit of base64 integer conversions
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
package main | |
import ( | |
"fmt" | |
) | |
func main() { | |
fmt.Println(i_to_base64(500)) | |
} | |
func i_to_base64(num int) string { | |
b64 := "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-" | |
base := len(b64) | |
str := "" | |
for num > 0 { | |
r := num % base | |
num -= r | |
num /= base | |
str = string(b64[r]) + str | |
} | |
return str | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment