Giter VIP home page Giter VIP logo

baseconv's Introduction

baseconv - Base conversion

Base conversion

Version Build Status Coverage Status License

A Go module for converting between different bases, e.g., decimal ↔ binary, octal ↔ hexadecimal

Installing

go get go.dkinom.dev/baseconv

Usage

See example/main.go

Hexadecimal ↔ Base58

hexadecimalToBase58Converter, _ := baseconv.NewBaseConversion("0123456789abcdef", baseconv.Base58)

base58Value, _ := hexadecimalToBase58Converter.Convert("415a59758fb933b6049b050a556dd4d916b7b483f6966615")
// base58Value == "6xZA4Qt9vH7rePWeT5WLaVUZNjB6u6rGc"

hexadecimal, _ := hexadecimalToBase58Converter.Inverse().Convert("GjWGF6jERR9ymrC1bHcGmsJYkLMDoaySr")
// hexadecimal == "ac93c8d619c76f823f184110759b278f246cc7cc3cadcac3"

Decimal (emoji) ↔ Hexadecimal

decimalEmojiToHexadecimalConverter, _ := baseconv.NewBaseConversion(
  "0️⃣1️⃣2️⃣3️⃣4️⃣5️⃣6️⃣7️⃣8️⃣9️⃣", baseconv.Base16,
  options.BaseConversion().
    SetZeroPadding(true),
)

hexadecimal, _ := decimalEmojiToHexadecimalConverter.Convert("5️⃣1️⃣9️⃣6️⃣6️⃣")
// hexadecimal == "0CAFE"

decimalEmoji, _ := decimalEmojiToHexadecimalConverter.Inverse().Convert("DEADC0DE")
// decimalEmoji == "3️⃣7️⃣3️⃣5️⃣9️⃣2️⃣9️⃣0️⃣5️⃣4️⃣"

Exported alphabets

  • Base2 - 01
  • Base3 - 012
  • Base4 - 0123
  • Base5 - 01234
  • Base6 - 012345
  • Base8 - 01234567
  • Base10 - 0123456789
  • Base12 - 0123456789AB
  • Base16 - 0123456789ABCDEF
  • Base32 - ABCDEFGHIJKLMNOPQRSTUVWXYZ234567
  • Base32hex - 0123456789ABCDEFGHIJKLMNOPQRSTUV
  • Base36 - 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
  • Base58 - 123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz
  • Base62 - 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
  • Base64 - ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
  • Base64url - ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_

Syntax

NewBaseConversion(from string, to string, opts ...*options.BaseConversionOptions) (*baseConversion, error)

from - String of numeral symbols representing the digits of from numeral system.

to - String of numeral symbols representing the digits of to numeral system.

See documentation for more

License

MIT

baseconv's People

Contributors

dkin-om avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.