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

funary

v1.0.0

Published

Arbitrary precision binary operations library for Javascript.

Downloads

23

Readme

funary

npm version Build Status Dependency Status

Arbitrary precision binary operations library for Javascript.

Table of contents

Install

NPM

npm install funary
var funary = require('funary'); 

Clientside

<script src="funary.js"></script>

Logic gates

The library has XOR,AND,OR,NAND,XNOR, and NOR logic gates.

var funary = require('funary'); 
funary.gates.and([1,1,1,1,1,0]) //0
funary.gates.and([1,1,1,1,1,1]) //1
funary.gates.xor([0,0,0,0,1,0]) //1
funary.gates.xor([1,0,0,0,0,1]) //0
funary.gates.or([0,0,0,0,0,1]) //1
funary.gates.or([0,0,0,0]) //0

Bitwise operations & bit shifts

Bitwise operations and bit shifts for bit manipulation.

var funary = require('funary');
//Bitwise operations. Similar selection to gates. AND,OR , ... etc.
funary.bitwise.and([0,1,0,1,0,1,0,1,1,1],[1,0,0,0,1,1,1,1,0,1]) //[0,0,0,0,0,1,0,1,0,1]
//   0101010111
//&  1000111101
//-------------
//   0000010101
funary.bitwise.or([0,1,0,1,0,1,0,1,1,1],[1,0,0,0,1,1,1,1,0,1]) //[1,1,0,1,1,1,1,1,1,1]
//   0101010111
//|  1000111101
//-------------
//   1101111111
funary.bitwise.xnor([0,1,0,1,0,1,0,1,1,1],[1,0,0,0,1,1,1,1,0,1]) //[0,0,1,0,0,1,0,1,0,1]
//     0101010111
//XNOR 1000111101
//---------------
//     0010010101

//Bit shifts
funary.left([0,0,1,0,1,1],2) //[1,0,1,1,0,0]
funary.right([0,0,1,0,1,1],2) //[0,0,0,0,1,0]

Big endian operations

Operations done in Big endian. Most significant digit in smallest address

Big endian arithmetic

Arithmetic operations. Any two arrays with any length.

var funary = require('funary');
//Addition
funary.big.NADDER([0,1,0,1,0,1,0,1,1,1],[1,0,0,0,1,1,1,1,0,1]) //[1,1,1,0,0,1,0,1,0,0]
//  0101010111
//+ 1000111101
//------------
//  1110010100

//Multiplication
funary.big.NMULTIPLY([1,0,1,0,1,1,0,0,1],[1,1,1,0,0,1,1,1]) //[1,0,0,1,1,0,1,1,1,0,1,0,0,1,1,1,1]
//          101011001
//X          11100111
//-------------------
//  10011011101001111

Big endian encoders & decoders

Encode and decode arrays of any size.

var funary = require('funary');
//Encoders
funary.big.NENCODE([0, 0, 0, 0, 0, 0, 0, 1]) //[0, 0, 0]
funary.big.NENCODE([0, 0, 0, 0, 0, 1, 0, 0]) //[0, 1, 0]
funary.big.NENCODE([0, 0, 0, 0, 0, 0, 1, 0]) //[0, 0, 1]

funary.big.NENCODE([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0]) //[0, 0, 1, 0]
funary.big.NENCODE([0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) //[1, 1, 1, 0]

//Decoders
funary.big.NDECODE([0,0,0]) //[0, 0, 0, 0, 0, 0, 0, 1]
funary.big.NDECODE([0,0,1]) //[0, 0, 0, 0, 0, 0, 1, 0]
funary.big.NDECODE([0,1,0]) //[0, 0, 0, 0, 0, 1, 0, 0]

funary.big.NDECODE([0,0,1,0]) //[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0]
funary.big.NDECODE([1,1,1,0]) //[0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

Big endian multiplexers & demultiplexers

var funary = require('funary');
//Multiplexing
//                   selectors inputs
funary.big.NMULTIPLEX([0,0],[0,0,0,0]) //0
funary.big.NMULTIPLEX([0,0],[0,0,0,1]) //1
funary.big.NMULTIPLEX([0,1],[0,0,0,0]) //0
funary.big.NMULTIPLEX([0,1],[0,0,1,0]) //1

funary.big.NMULTIPLEX([0,1,1],[0,0,0,0,0,0,0,0]) //0
funary.big.NMULTIPLEX([0,1,1],[0,0,0,0,1,0,0,0]) //1

//Demultiplexing
//                     selectors inputs
funary.big.NDEMULTIPLEX([0,0],0) //[0, 0, 0, 0]
funary.big.NDEMULTIPLEX([0,0],1) //[0, 0, 0, 1]
funary.big.NDEMULTIPLEX([0,1],0) //[0, 0, 0, 0]
funary.big.NDEMULTIPLEX([1,0],1) //[0, 1, 0, 0]

funary.big.NDEMULTIPLEX([0,0,1],1) //[0, 0, 0, 0, 0, 0, 1, 0]
funary.big.NDEMULTIPLEX([0,0,1],0) //[0, 0, 0, 0, 0, 0, 0, 0]

Big endian conversions

Conversions between formats

var funary = require('funary');
//Decimal to binary
funary.big.toUnsignedBinary(12) //[1, 1, 0, 0]
//Binary to decimal
funary.big.toUnsignedDecimal([1, 1, 0, 1]) //13

Little endian operations

Operations done in Little endian. Most significant digit in largest address

Little endian arithmetic

Arithmetic operations. Any two arrays with any length.

var funary = require('funary');
//Addition
funary.little.NADDER([0,1,0,1,0,1,0,1,1,1],[1,0,0,0,1,1,1,1,0,1]) //[1,1,0,1,1,0,0,1,0,1,1]
//  0101010111
//+ 1000111101
//-------------
//  11011001011

//Multiplication
funary.little.NMULTIPLY([1,1,1,0,1,0,1,0,1],[1,0,1,1]) //[1,1,0,1,0,1,1,0,1,0,0,0,1]
//  111010101
//X 1011
//---------------
//  1101011010001

Little endian encoders & decoders

Encode and decode arrays of any size.

var funary = require('funary');
//Encoders
funary.little.NENCODE([1, 0, 0, 0, 0, 0, 0, 0]) //[0,0,0]
funary.little.NENCODE([0, 1, 0, 0, 0, 0, 0, 0]) //[1,0,0]
funary.little.NENCODE([0, 0, 1, 0, 0, 0, 0, 0]) //[0,1,0]

funary.little.NENCODE([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]) //[0,1,0,1]
funary.little.NENCODE([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0]) //[1,1,0,1]

//Decoders
funary.little.NDECODE([0,0,0]) //[1, 0, 0, 0, 0, 0, 0, 0]
funary.little.NDECODE([1,0,0]) //[0, 1, 0, 0, 0, 0, 0, 0]
funary.little.NDECODE([0,1,0]) //[0, 0, 1, 0, 0, 0, 0, 0]

funary.little.NDECODE([0,1,0,1]) //[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]
funary.little.NDECODE([1,1,0,1]) //[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0]

Little endian multiplexers & demultiplexers

var funary = require('funary');
//Multiplexing
//                   selectors inputs
funary.little.NMULTIPLEX([0,0],[0,0,0,0]) //0
funary.little.NMULTIPLEX([0,0],[1,0,0,0]) //1
funary.little.NMULTIPLEX([0,1],[0,0,0,0]) //0
funary.little.NMULTIPLEX([0,1],[0,0,1,0]) //1

funary.little.NMULTIPLEX([0,1,1],[0,0,0,0,0,0,0,0]) //0
funary.little.NMULTIPLEX([0,1,1],[0,0,0,0,0,0,1,0]) //1

//Demultiplexing
//                     selectors inputs
funary.little.NDEMULTIPLEX([0,0],0) //[0, 0, 0, 0]
funary.little.NDEMULTIPLEX([0,0],1) //[1, 0, 0, 0]
funary.little.NDEMULTIPLEX([0,1],0) //[0, 0, 0, 0]
funary.little.NDEMULTIPLEX([0,1],1) //[0, 0, 1, 0]

funary.little.NDEMULTIPLEX([0,0,1],1) //[0, 0, 0, 0, 1, 0, 0, 0]
funary.little.NDEMULTIPLEX([0,0,1],0) //[0, 0, 0, 0, 0, 0, 0, 0]

Little endian conversions

Conversions between formats

var funary = require('funary'); 
//Decimal to binary
funary.little.toUnsignedBinary(12) //[0, 0, 1, 1]
//Binary to decimal
funary.little.toUnsignedDecimal([1, 1, 1, 0, 1]) //23

Full & Half adders

var funary = require('funary'); 
//Little endian by default
funary.FA([1,1,1]) //[1,1]
funary.FA([1,1,0]) //[0,1]
funary.FA([1,0,1]) //[0,1]
funary.FA([0,0,1]) //[1,0]
funary.HA([1,0]) //[1,0]
funary.HA([1,1]) //[0,1]

General conversions

var funary = require('funary');
//Array of bits to string
funary.arrayToString([1,1,0,1,0,1,1,1,1,0,0]) //"11010111100"
//String to array of bits
funary.stringToArray('001000001111') //[0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1]
//Convert bool array to binary
funary.boolArrayToBinary([false,false,true,true,false]) //[0,0,1,1,0]
//Convert binary array to bool
funary.binaryArrayToBool([0,1,0,1,0,0]) //[false,true,false,true,false,false]

Other operations

var funary = require('funary'); 
funary.not(1) //0
funary.not(0) //1
funary.invert([0,1,1,0,0,1,1,1]) //[1,0,0,1,1,0,0,0]
//Truncation
funary.righttrunc([1, 1, 1, 0, 1, 0, 1, 0],4) //[1, 1, 1, 0]
funary.lefttrunc([1, 1, 1, 0, 1, 0, 1, 0],5) //[0, 1, 0, 1, 0]
//Number of ones
funary.countones([1,0,1,0,1,1,1]) //5
//Combinations
funary.getCombinations(3) //[[1,1,1],[0,1,1],[1,0,1],[0,0,1],[1,1,0],[0,1,0],[1,0,0],[0,0,0]]
//Zeros
funary.zeros(4) //[0,0,0,0]
//Add zeros
funary.addzeros([1],3) //[1,0,0,0]
//UNshift zeros
funary.unshiftzeros([1],3) //[0,0,0,1]

Related projects

DLCS npm version

Digital Logic Circuit Simulation library. Create and simulate high level integrated circuits. Depends on funary.