Skip to content
This repository has been archived by the owner on Jul 20, 2020. It is now read-only.

Latest commit

 

History

History
45 lines (36 loc) · 842 Bytes

README.md

File metadata and controls

45 lines (36 loc) · 842 Bytes

BaseConv

Utility to convert numbers from base 10 integers to base X strings and back again. Based on Django's baseconv.py utility.

Documentation

Read the documentation at godoc.org.

Usage

func Example() {
	encoded := baseconv.Base36.Encode(1234)
	fmt.Println(encoded)

	decoded, err := baseconv.Base36.Decode(encoded)
	if err != nil {
		panic(err)
	}
	fmt.Print(decoded)

	// Output:
	// ya
	// 1234
}

func Example_base11() {
	base11, err := baseconv.New("0123456789-", "$")
	if err != nil {
		panic(err)
	}

	encoded := base11.Encode(-1234)
	fmt.Println(encoded)

	decoded, err := base11.Decode(encoded)
	if err != nil {
		panic(err)
	}
	fmt.Print(decoded)

	// Output:
	// $-22
	// -1234
}