Skip to content

BlackGlory/bigint-base

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

bigint-base

Yet another base conversion library, but using BigInt.

Install

npm install --save bigint-base
# or
yarn add bigint-base

Usage

import { convertDecimalToBase, convertBaseToDecimal } from 'bigint-base'

const hex = '0123456789abcdef'

const decToHex = convertDecimalToBase(hex)
const hexToDec = convertBaseToDecimal(hex)

decToHex(16n) // '10'
hexToDec('10') // 16n

API

convertDecimalToBase

function convertDecimalToBase(alphabet: string, val: bigint): string
function convertDecimalToBase(alphabet: string): (val: bigint) => string

convertBaseToDecimal

function convertBaseToDecimal(alphabet: string, val: string): bigint
function convertBaseToDecimal(alphabet: string): (val: string) => bigint

convertBaseToBase

function convertBaseToBase(
  srcAlphabet: string
, destAlphabet: string
, val: string
): string
function convertBaseToBase(
  srcAlphabet: string
, destAlphabet: string
): (val: string) => string