Skip to content

CLI to help with various binary calculations and conversions.

Notifications You must be signed in to change notification settings

theodrosyimer/binez

Repository files navigation

binez

Table of Contents

pronounce: bin-ee-zee

Motivation

I was working on a project where I had to calculate the range of a given number of bits and the size limit of a given number of bits in a given memory size in kilobytes for base 2 (binary). I found myself constantly having to do the same calculations over and over again and I was getting frustrated. So,binez was born out of that frustration. It's a simple command line tool that can do the following:

  • convert a given number in megabytes to bytes (e.g. 1MB to 1_048_576 bytes)
  • calculate the range of a given number of bits (e.g. for an unsigned 8 bits, the range is 0-255)
  • calculate the range of a given number of bytes (e.g. for 2 unsigned bytes, the range is 0-65535)
  • calculate what is the size limit of a given memory size in kilobytes for a given number in bits (e.g. for a 16-bit integer in 32KB of memory, the size/length limit is 16384)

Prerequisites

Quick start

Install

TODO: Publish to npm

git clone https://github.com/theodrosyimer/binez@latest
cd binez
npm install
npm run build
npm link

Usage

Examples

Convert 6MB to bytes:

binez convert 6

Calculate the range of a given number of unsigned bits:

binez range -b 8

Calculate the range of a given number of unsigned bytes:

binez range -B 2

Calculate the range of a given number of signed bits:

binez range -b -8

Calculate the range of a given number of signed bytes:

binez range -B -2

Calculate the size limit of a given number in bits in a given memory size in kilobytes:

binez mem -b 16 -ms 32

For both the range and mem commands, you can use the -l or --locale flag to specify the locale to use for formatting the output. The default locale is en-US. The supported locales are the same as those supported by the Intl object in JavaScript and can be found here as text or here as json if you prefer.

For example, to convert a number of bits to bytes in French, you can use the following command:

binez range -b 16 -l fr

Documentation

convert

convert <number> [ -l --locale = 'en-US' ]

Convert a given number of megabytes to bytes:

binez convert <number>

range

range [ [ -b --bits | -B --bytes ] <number> ][ -l --locale = 'en-US' ]

Calculate the range of a given unsigned/signed number in bits:

binez range -b <bits> -l <locale>

Calculate the range in a given unsigned/signed number in bytes:

binez range -B <bytes> -l <locale>

NOTE:

  1. The maximum number of bits for which the range can be calculated is 512 and the maximum number of bytes for which the range can be calculated is 64. This is because the maximum number of bits for which a number can be represented in JavaScript is 2^53 - 1 and the maximum number of bytes for which a number can be represented in JavaScript is 2^53 - 1 / 8.
  2. The -l or --locale flag return an error message if the locale is not supported by the Intl object in JavaScript and seems to be constraint to be a string of length between 2 and 8. This is because the Intl object in JavaScript only supports locales that are between 2 and 8 characters long.

mem

mem -b[ --bits ] <number> -ms [ --memory-size ] <number> [ -l --locale = 'en-US' ]

Calculate the size limit of a given unsigned number in bits in a given memory size in kilobytes:

binez mem -b <bits> -ms <memory-size> -l <locale>

Contribute

Clone the repo

git clone https://github.com/theodrosyimer/binez@latest
cd binez

Install dependencies

npm install

Develop

To start developing, you will need to first build the project:

npm run build

Then link the project to the global @thyi/binez package and start the development server:

npm run link-cli
npm run dev

To start/reset the development environment in one command, you can use the following command:

npm run dev:reset

Run tests

npm test

Submit a pull request

If you'd like to contribute code, documentation, or any other improvements, please fork the project, make your changes, and submit a pull request.

If you're unsure about adding a feature or fixing a bug, create an issue to discuss it first.

License

MIT © Theodros Yimer

About

CLI to help with various binary calculations and conversions.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published