# 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:

`result, err := basexx.Digits(412, basexx.Base30)`

To decode the base30 digit string `"fr"`

:

`result, err := basexx.Value("fr", basexx.Base30)`

To convert a digit string `x`

in base `from`

to a new digit string in base `to`

:

```
var (
src = basexx.NewBuffer(x, from)
destbuf = make([]byte, basexx.Length(from, to, len(x)))
dest = basexx.NewBuffer(destbuf, to)
)
_, err := Convert(dest, src)
if err != nil { ... }
result := dest.Written()
```

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) Encode(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) Decode(digit byte) (int64, error) {
if digit < '0’ || digit > '9' {
return 0, errors.New("invalid encoded digit")
}
return int64(9 - (digit - '0’))
}
```