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

Utility to convert numbers from base 10 integers to base X strings and back again.

License

Notifications You must be signed in to change notification settings

enricofoltran/baseconv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
}