# README
Basexx - Convert between digit strings and various number bases
This is basexx, a package for converting numbers to digit strings in various bases and vice versa.
Usage
To get the Base30 encoding of the number 412:
var sb strings.Builder
if err := basexx.EncodeInt64(&sb, 412, basexx.Base30); err != nil { ... }
result := sb.String()
To decode the Base30 digit string "fr"
:
result, err := basexx.DecodeString("fr", basexx.Base30)
To convert a digit string x
in base from
to a new digit string in base to
:
result, err := basexx.Convert(x, from, to)
To define your own new number base:
// ReverseBase10 uses digits '9' through '0' just to mess with you.
type ReverseBase10 struct{}
func (ReverseBase10) N() int64 { return 10 }
func (ReverseBase10) Digit(val int64) (byte, error) {
if val < 0 || val > 9 {
return 0, errors.New("digit value out of range")
}
return byte('9' - val), nil
}
func (ReverseBase10) Val(digit byte) (int64, error) {
if digit < '0’ || digit > '9' {
return 0, errors.New("invalid encoded digit")
}
return int64(9 - (digit - '0’))
}
# Packages
No description provided by the author
# Functions
Convert converts a string from one base to another.
Decode decodes an integer expressed as a string in the given base.
DecodeString decodes a string in the given base.
Encode encodes inp as a string in the given base.
EncodeInt64 encodes an integer as a string in the given base.
NewTableBase returns a new TableBase initialized from the given digits.
# Constants
Base10 uses digits "0" through "9".
Base12 uses digits "0" through "9" plus "a" and "b".
Base16 uses digits "0" through "9" plus "a" through "f".
Base2 uses digits "0" and "1".
Base32 uses digits "0" through "9" plus "a" through "v".
Base36 uses digits "0" through "9" plus "a" through "z".
Base8 uses digits "0" through "7".
# Variables
Base30 uses digits 0-9, then lower-case bcdfghjkmnpqrstvwxyz.
Base50 uses digits 0-9, then lower-case bcdfghjkmnpqrstvwxyz, then upper-case BCDFGHJKMNPQRSTVWXYZ.
Base62 uses digits 0..9, then a..z, then A..Z.
Base94 uses all printable ASCII characters (33 through 126) as digits.
Binary is base 256 encoded the obvious way: digit value X = byte(X).
ErrInvalid is returned when a digit or a value is out of range.
# Interfaces
Base is the abstract type of a number base.
# Type aliases
Alnum is a type for bases from 2 through 36, where the digits for the first 10 digit values are '0' through '9' and the remaining digits are 'a' through 'z'.