npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

all-your-base

v0.3.0

Published

convert from/to binary, octal, hexadecimal, decimal values

Downloads

61

Readme

All your base

Convert from one base to another

Installation

npm install all-your-base

Install as command line tool

npm link from your local repo's root. The executable is named ayb.

Usage

Use this in your own scripts and/or as a quick stand-alone command-line tool.

From a script

var ayb = require('all-your-base');

// convert 'abcdef', from base-16 to base-2
ayb.parseInt('abcdef', 16, 2)

// Or directly call the conversion methods
ayb.decToBin(22);
ayb.hexToDec('10000');

From command line

First, type npm link from your local repo's root directory. The executable is named ayb. Name a method & space separate your arguments.

$ ayb parseInt 65536 10 16
10000
$ ayb hexToDec 10000
65536

Supported bases

| base/radix | name | module's abbr. | |:-----------|:------------|:---------------| | base 2 | binary | bin | | base 8 | octal | oct | | base 10 | decimal | dec | | base 16 | hexadecimal | hex |

List of all operations

Here's an exhaustive list for your reference.

parseInt

The native parseInt method will let you convert another base to base-10. But the one provided in this module will let you convert to another base. It's merely a wrapper for the other conversion methods.

  • ayb.parseInt(value, fromBase, toBase)
    • value, String. The value in the base you want to convert.
    • fromBase, Number. Specify the base you are converting from.
      • If you are using a script & pass in undefined, then it is assumed you are converting from base-10
    • toBase, Number.Specify the base you are converting to.
      • If you don't pass in anything, then it is assumed you are converting from base-10.

For the following methods, pass in a numerical as a string.

From binary
  • binToDec
  • binToHex
  • binToOct
From octal
  • octToDec
  • octToBin
  • octToHex
From decimal
  • decToBin
  • decToHex
  • decToOct
From hexadecimal
  • hexToDec
  • hexToBin
  • hexToOct

The pattern: [old]To[New]
[old] is the first three letters of the base you are converting from.
[New] is the first three letters of the base to convert to.

Notice, the function name is lowerCamelCased.


Helpful links

Learn more about different bases.