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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@turing-machine-js/library-binary-numbers

v6.0.1

Published

A standard library for working with binary numbers

Readme

@turing-machine-js/library-binary-numbers

build npm (tag)

Binary arithmetic on a 5-symbol alphabet ( , ^, $, 0, 1) supporting multiple numbers per tape. Numbers are delimited by ^…$ markers — the markers cost extra states per algorithm but enable inter-number navigation. Side-by-side with @turing-machine-js/library-binary-numbers-bare, which drops the markers for smaller graphs at the cost of single-number-only operation.

Install

npm install @turing-machine-js/machine @turing-machine-js/library-binary-numbers

@turing-machine-js/machine is a peer dependency.

Concept

A number is a sequence of 0/1 cells delimited by ^ (start) and $ (end). Several numbers can sit on one tape, separated by blanks.

…blank ^101011$ blank ^110010$ blank…
       ╰─ 43 ─╯       ╰─ 50 ─╯

Examples:

  • ^$ represents 0
  • ^1$ represents 1
  • ^10$ represents 2
  • ^11$ represents 3

Negative numbers are not currently supported.

Algorithms

| name | what it does | |---|---| | goToNumber | move the head to the current number's $ | | goToNextNumber | move the head to the next number (rightward) | | goToPreviousNumber | move the head to the previous number (leftward) | | goToNumbersStart | move the head to the current number's ^ | | deleteNumber | erase the current number entirely | | invertNumber | flip every bit (01) | | normalizeNumber | erase leading zeros (preserving ^$ for the value zero) | | plusOne | add 1 to the number; extends leftward on overflow (111 + 1 = 1000) | | minusOne | subtract 1, computed via ~(~x + 1) — composes invertNumberplusOneinvertNumbernormalizeNumber | | minusOneFast | direct borrow propagation; smaller than minusOne and auto-normalizes |

To use these, the tape block must come from getTapeBlock() — that's the one that interns the ^/$/01 patterns the states key against.

Usage

import { Tape, TuringMachine } from '@turing-machine-js/machine';
import binaryNumbers from '@turing-machine-js/library-binary-numbers';

const tapeBlock = binaryNumbers.getTapeBlock();
const tape = new Tape({
  alphabet: tapeBlock.alphabets[0],
  symbols: '^101$'.split(''), // binary 5
});

tapeBlock.replaceTape(tape);

const machine = new TuringMachine({ tapeBlock });

await machine.run({ initialState: binaryNumbers.states.plusOne });

console.log(tape.symbols.join('').trim()); // "^110$" (binary 6)

To run several algorithms in sequence on the same value, reuse the same TapeBlock across machine.run(...) calls — every state in binaryNumbers.states halts cleanly with the head positioned for the next algorithm to pick up.

How it compares to the bare library

Both libraries solve the same arithmetic problem; the trade is alphabet symbols vs state-graph size.

| algorithm | this library (5-symbol) | bare library (3-symbol) | |---|---|---| | plusOne | 5 states | 3 states | | minusOne | 17 / 10 (minusOne / minusOneFast) | 3 states | | invertNumber | 5 states | 2 states | | normalizeNumber | 7 states | 2 states | | multi-number on tape? | yes — goToNumber, goToNextNumber, etc. | no | | head-position flexibility | anywhere on the number | leftmost digit | | minusOne auto-normalizes? | yes — minusOneFast chains into normalizeNumber | no — leading 0 kept |

The extra states this library spends are mostly bookkeeping for the ^/$ markers (planting ^ on left-overflow, sweeping past it on entry, etc.). The pay-off is multi-number-per-tape support and head-position flexibility — goToNumber / goToNextNumber / goToPreviousNumber / deleteNumber / goToNumbersStart have no counterpart in the bare library.

For a teaching context, both libraries shipping in parallel makes the cost of representation choices tangible.

See the rendered Mermaid graphs for every state in states.md (regenerated via npm run docs:states from the repo root; the spec at src/graphs.spec.ts only verifies structural properties of the graphs, not the markdown file).

Links