basesystems 

This project contains code for encoding/decoding numeric basesystems in Haskell.
It's implemented for the Haskell bytestring types and provides a type-class
interface:
class BaseSystem a where
encoder :: a -> ShortByteString -> String
decoder :: a -> String -> Maybe ShortByteString
The library creates more BaseSystem classes with methods on normal
ByteString in Data.BaseSystem.Strict and LazyByteString
in Data.BaseSystem.Lazy. See the example.
Coverage
This project aims to implement the multibase specification's basesystems list.
Currently, the following basesystems are supported:
base2 for binary
base10 for decimal
base16upper and base16lower for hexadecimal
base32upper and base32lower for base32
base32upperNP and base32lowerNP for base32, without padding
base32hexupper and base32hexlower for hex-style base32
base32hexupperNP and base32hexlowerNP for hex-style base32, without
padding
base58btc for Bitcoin's base58
base64 and base64url for base64 variants
base64NP and base64urlNP for base64 variants, without padding
Example
For an example of using basesystems, we can do the following in GHCI:
Set OverloadedStrings so Strings can act as Text data and import the
needed functions. Then import the basesystem functions and packValue from
XCodec.Transcoder to convert a number value directly into bytes.
This shows how we can take the binary value of 123 and display it in various
number systems:
λ> import Data.BaseSystem (encoder, decoder, base2, base10, base16lower, base32lower)
λ> import XCodec.Transcoder (packValue)
λ> :t encoder
encoder :: BaseSystem a => a -> ShortByteString -> Text
λ> :t decoder
decoder :: BaseSystem a => a -> Text -> Maybe ShortByteString
λ> encoder base2 $ packValue (123 :: Int)
"1111011"
λ> encoder base16lower $ packValue (123 :: Int)
"7b"
λ> encoder base32lower $ packValue (123 :: Int)
"pm======"
We can also use encoders and decoders to translate one numeric representation to
another:
λ> encoder base10 <$> decoder base2 "1111011"
Just "123"
λ> encoder base10 <$> decoder base16lower "7b"
Just "123"
λ> encoder base10 <$> decoder base32lower "pm======"
Just "123"
Development
This project is part of ipfshs; unit tests are
provided on the main page and bugs can be reported on its ticket tracker. Patches and pull requests can be submitted with
git send-email. To build and test this project
against all of ipfshs read this
section on setting up an ipfshs development environment.
This project can also be built as a standalone library with cabal.
$ git clone https://git.sr.ht/~z0/basesystems
$ cd basesystems
$ cabal build
Licensing
The basesystems project and its modules are free software and licensed under the
BSD 3-clause license. See LICENSE.txt.
Copyright © 2026 Zoey McBride | zoeymcbride@mailbox.org