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

s-binary

v0.0.13

Published

Simple operations for binary strings

Downloads

20

Readme

s-binary

Work in progress

NPM version Dependencies build status NPM license Stability

Usage example

var binary = require('s-binary');

binary.toInt('11001100'); // returns 204

// 8bit 5 - 9
var five = binary.toBinary(5, 8); // '00000101'
var nine = binary.toBinary(9, 8); // '00001001'
var negativeNine = binary.complement(nine); // '11110111'
var sum = binary.add(five, negativeNine); // '11111100'
var checkAnswer = binary.complement(sum); // '00000100'

binary.toInt(checkAnswer); // 4

Installation

npm install --save s-binary

Available methods

This module assumes big-endian byte order

Unit conversion

binary to integer
binary.toInt('11001100'); // returns 204
binary to hex
binary.toHex('11001100'); // returns 'cc'
binary to Unicode
binary.toUnicode('0110100001101001'); // returns 'hi'
string/integer/buffer to binary
binary.toBinary(204); // returns '11001100'
binary.toBinary('foo'); // returns '011001100110111101101111'

Arithmetic

Simple addition
binary.add('111', '1'); // returns '1000'
Bit addition
binary.addBits('1', '1'); // returns ['0', '1']
// ------------------------------- sum ^ -- ^ carry
Multiplication
binary.multiply('1010', '10'); // returns '10100'
//            10 ^     2 ^              20 ^
Division
binary.divide('1010', '101'); // returns '10'
//          10 ^     5 ^                2 ^

Logic

NOT
binary.not('1011'); // returns '0100'
AND
binary.and('101', '110'); // returns '100'
OR
binary.or('101', '110'); // returns '111'
XOR
binary.xor('101', '110'); // returns '011'
NAND
binary.nand('101', '110'); // returns '011'
NOR
binary.nor('101', '110'); // returns '000'
Two's complement
binary.complement('00000101'); // returns '11111011'

Helper methods

(Left) pad
binary.pad('01', 4); // returns '0001' (left pad)
Equalize lengths by padding shorter value
binary.equalize('11', '0001'); // returns ['0011', '0001']
Split
binary.split('1111111100000000', 8); // returns ['11111111', '00000000']
LSB (get least significant bits)

Last bit from each byte. Note: bytes can be of any length.

var data = ['01000100', '11001100', '01010101'];
binary.lsb(data); // returns '001'