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

simple-binary-utils

v1.1.1

Published

Utilities for working with binary strings.

Downloads

11

Readme

Simple Binary Utils

This is a package that helps work with binary string representations of numbers and converted strings. You can convert any number or any text to binary and perform safe math operations on it and get outputs, thus resulting in a pseudo-cryptographic method of encoding your data. This package was designed as a helper for implementing the Fiege-Fiat-Shamir algorithm for text instead of numbers (thereby allowing conversion of strings into integer representations, performing math, and getting a different string result for the proof). Written using typescript.

Functions

Utilities

BinaryUtils.isBinaryString(str: string): string: Determine if a string is a proper binary string.

BinaryUtils.fixLength(str: string): string: Fixes a binary string by left-padding it with the appropriate number of 0's to complete a binary word.

BinaryUtils.findBestLength(...strs: string[]): number: Finds the best length for all of the strings to have (the longest of the supplied parameters).

BinaryUtils.toBinary(a: number): string: Converts a number to binary.

BinaryUtils.toDecimal(a: string): number: Converts a binary string back to a decimal.

BinaryUtils.stringToBinary(str: string): string: Converts a regular text string into a binary representation.

BinaryUtils.binaryToString(str: string): string: Converts a binary string back into it's text representation.

Math

BinaryUtils.add(a: string, b: string): string: Adds two binary strings and returns the resulting binary string

BinaryUtils.subtract(a: string, b: string): string: Subtracts two binary strings and returns the resulting bianry string

BinaryUtils.multiply(a: string, b: string): string: Multiplies two binary strings and returns the resulting bianry string (NOT WORKING) BinaryUtils.divide(a: string, b: string): string: Divides two binary strings and returns the resulting bianry string

BinaryUtils.power(base: string, exponent: string): string: Raises a binary string base to the power of exponent and returns resulting binary string.

Examples

Converting a number to binary and performing an addition on it.

const a = BinaryUtils.toBinary(1234);
const b = BinaryUtils.toBinary(1234);

const result = BinaryUtils.add(a, b); // Returns: 2468

Simple conversion of text to binary

const bin = BinaryUtils.stringToBinary('hello world');

String math

const strA = BinaryUtils.stringToBinary('hello world');
const strB = BinaryUtils.stringToBinary('goodbye world');
const result = BinaryUtils.add(strA, strB); // Returns: result of addition between binary 'hello world' and binary 'goodbye world'

Reversing string math

const strA = BinaryUtils.stringToBinary('hello world');
const strB = BinaryUtils.stringToBinary('goodbye world');
const added = BinaryUtils.add(strA, strB); // Returns: result of addition between binary 'hello world' and binary 'goodbye world'
const result = BinaryUtils.subtract(added, strB); // Returns: 'hello world'

Contributing

Fork and make a Pull Request with your code. No guarantee it'll be accepted.

Known Caveats

1.0.x:

  • BinaryUtils.divide does not work. I don't know how to implement that logic as of yet.

Planned Features

1.1.0: Add tests for and fix the non-working BinaryUtils.divide method. Could be pushed to 2.0.0; Add typescript definitions. 2.0.0: Rework the whole thing to work with indefinitely-sized buffers to perform operations instead of raw strings. No guarantees on a 2.0.x release.