base36

package module
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 19, 2022 License: MIT Imports: 2 Imported by: 80

README

About

GoDoc

Implements Base36 encoding and decoding, which is useful to represent large integers in a case-insensitive alphanumeric way.

Examples

import "github.com/martinlindhe/base36"

fmt.Println(base36.Encode(5481594952936519619))
// Output: 15N9Z8L3AU4EB

fmt.Println(base36.Decode("15N9Z8L3AU4EB"))
// Output: 5481594952936519619

fmt.Println(base36.EncodeBytes([]byte{1, 2, 3, 4}))
// Output: A2F44

fmt.Println(base36.DecodeToBytes("A2F44"))
// Output: [1 2 3 4]

License

Under MIT

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(s string) uint64

Decode decodes a base36-encoded string.

Example
package main

import (
	"fmt"

	"github.com/martinlindhe/base36"
)

func main() {
	fmt.Println(base36.Decode("15N9Z8L3AU4EB"))
}
Output:

5481594952936519619

func DecodeToBytes

func DecodeToBytes(b string) []byte

DecodeToBytes decodes a base36 string to a byte slice, using alphabet.

Example
package main

import (
	"fmt"

	"github.com/martinlindhe/base36"
)

func main() {
	fmt.Println(base36.DecodeToBytes("A2F44"))
}
Output:

[1 2 3 4]

func Encode

func Encode(value uint64) string

Encode encodes a number to base36.

Example
package main

import (
	"fmt"

	"github.com/martinlindhe/base36"
)

func main() {
	fmt.Println(base36.Encode(5481594952936519619))
}
Output:

15N9Z8L3AU4EB

func EncodeBytes

func EncodeBytes(b []byte) string

EncodeBytes encodes a byte slice to base36 string.

Example
package main

import (
	"fmt"

	"github.com/martinlindhe/base36"
)

func main() {
	fmt.Println(base36.EncodeBytes([]byte{1, 2, 3, 4}))
}
Output:

A2F44

func EncodeBytesAsBytes

func EncodeBytesAsBytes(b []byte) []byte

EncodeBytesAsBytes encodes a byte slice to base36.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL