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 🙏

© 2025 – Pkg Stats / Ryan Hefner

convert-binary

v1.0.0

Published

An NPM package to convert various data types to and from binary representation

Readme

Convert Binary

An NPM package to convert various data types to and from binary representation. Easily convert numbers, strings, hex, octal, and more to and from binary format.

Features

✅ Convert numbers, strings, hex, and more to binary
✅ Convert binary back to readable formats
✅ Supports floats, booleans, and bitwise operations
✅ No dependencies – lightweight and fast!


Installation

Install the package via npm:

npm install convert-binary

Importing

For CommonJS (Node.js Default)

const convert = require('convert-binary');

For ES Modules (ECMAScript Imports)

import convert from 'convert-binary';

Usage

Convert a number to binary

const { toBinaryFromNumber } = require('convert-binary');

console.log(toBinaryFromNumber(10));  
// Output: '1010'

Convert a string to binary

const { toBinaryFromString } = require('convert-binary');

console.log(toBinaryFromString("Hello"));  
// Output: '0100100001100101011011000110110001101111'

Convert binary to a number

const { binaryToNumber } = require('convert-binary');

console.log(binaryToNumber("1010"));  
// Output: 10

Convert binary to a string

const { binaryToString } = require('convert-binary');

console.log(binaryToString("0100100001100101011011000110110001101111"));  
// Output: 'Hello'

API Reference

Conversion Functions

| Function | Description | Example Input | Example Output | |---------------------------|------------------------------------------|---------------|-------------------------------------| | toBinaryFromNumber(num) | Converts a number to binary. | 10 | "1010" | | toBinaryFromString(str, encoding="utf-8") | Converts a string to binary. | "A" | "01000001" | | toBinaryFromHex(hexStr) | Converts a hex string to binary. | "A" | "1010" | | toBinaryFromOctal(octalStr) | Converts an octal string to binary. | "12" | "1010" | | toBinaryFromBoolean(bool) | Converts a boolean to binary. | true | "1" | | toBinaryFromFloat(floatNum) | Converts a floating point number to binary. | 5.75 | "01000000101110000000000000000000" |

Binary to Other Formats

| Function | Description | Example Input | Example Output | |-----------------------|--------------------------------------|--------------------------------------------|----------------| | binaryToNumber(binStr) | Converts a binary string to a number. | "1010" | 10 | | binaryToString(binStr, encoding="utf-8") | Converts binary to a string. | "01000001" | "A" | | binaryToHex(binStr) | Converts binary to hex. | "1010" | "A" | | binaryToOctal(binStr) | Converts binary to octal. | "1010" | "12" | | binaryToBoolean(binStr) | Converts binary to a boolean. | "1" | true | | binaryToFloat(binStr) | Converts binary to a float. | "01000000101110000000000000000000" | 5.75 |

Binary Utility Functions

| Function | Description | Example Input | Example Output | |-----------------------|--------------------------------------------------|---------------------|----------------| | padBinary(binStr, length) | Pads a binary string with leading zeros. | "101", 8 | "00000101" | | chunkBinary(binStr, chunkSize) | Splits a binary string into chunks. | "11001100", 4 | ["1100", "1100"]| | invertBinary(binStr) | Inverts (flips) binary bits. | "1010" | "0101" | | xorBinary(bin1, bin2) | Performs XOR operation on two binary strings. | "1100", "1010" | "0110" | | andBinary(bin1, bin2) | Performs AND operation on two binary strings. | "1100", "1010" | "1000" | | orBinary(bin1, bin2) | Performs OR operation on two binary strings. | "1100", "1010" | "1110" | | notBinary(binStr) | Performs NOT operation (bit inversion). | "1010" | "0101" | | shiftBinaryLeft(binStr, places) | Shifts a binary string left by n places. | "1010", 2 | "101000" | | shiftBinaryRight(binStr, places) | Shifts a binary string right by n places. | "1010", 2 | "10" |

Contributing

Want to improve convert-binary? Follow these steps:

  1. Fork the repo
  2. Create a new branch
  3. Commit your changes
  4. Push to your branch
  5. Submit a pull request!