{"id":13408720,"url":"https://github.com/jarun/bcal","last_synced_at":"2026-02-20T17:05:18.416Z","repository":{"id":45399286,"uuid":"68843078","full_name":"jarun/bcal","owner":"jarun","description":":1234: Bits, bytes and address calculator","archived":false,"fork":false,"pushed_at":"2025-02-17T22:28:26.000Z","size":532,"stargazers_count":684,"open_issues_count":0,"forks_count":41,"subscribers_count":7,"default_branch":"master","last_synced_at":"2026-02-12T07:24:50.903Z","etag":null,"topics":["calculator","cli","command-line","console","developer-tools","expression-evaluator","mathematics","standalone","storage","storage-unit-converter","terminal","unit-conversion"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jarun.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"jarun"}},"created_at":"2016-09-21T17:49:38.000Z","updated_at":"2026-02-09T23:16:37.000Z","dependencies_parsed_at":"2023-01-26T15:30:14.409Z","dependency_job_id":"9fa72ebf-180b-45db-b963-7ab68ad6f5e6","html_url":"https://github.com/jarun/bcal","commit_stats":{"total_commits":324,"total_committers":9,"mean_commits":36.0,"dds":0.09259259259259256,"last_synced_commit":"848545eac88abb6c54556a32564f793689dbe19a"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/jarun/bcal","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jarun%2Fbcal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jarun%2Fbcal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jarun%2Fbcal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jarun%2Fbcal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jarun","download_url":"https://codeload.github.com/jarun/bcal/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jarun%2Fbcal/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29658168,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-20T16:33:43.953Z","status":"ssl_error","status_checked_at":"2026-02-20T16:33:43.598Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["calculator","cli","command-line","console","developer-tools","expression-evaluator","mathematics","standalone","storage","storage-unit-converter","terminal","unit-conversion"],"created_at":"2024-07-30T20:00:54.788Z","updated_at":"2026-02-20T17:05:18.410Z","avatar_url":"https://github.com/jarun.png","language":"C","readme":"\u003ch1 align=\"center\"\u003ebcal\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://github.com/jarun/bcal/releases/latest\"\u003e\u003cimg src=\"https://img.shields.io/github/release/jarun/bcal.svg?maxAge=600\u0026label=rel\" alt=\"Latest release\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://repology.org/project/bcal/versions\"\u003e\u003cimg src=\"https://repology.org/badge/tiny-repos/bcal.svg?header=repos\" alt=\"Availability\"\u003e\u003c/a\u003e\n\u003ca href=\"https://circleci.com/gh/jarun/workflows/bcal\"\u003e\u003cimg src=\"https://img.shields.io/circleci/project/github/jarun/bcal.svg?label=CircleCI\" alt=\"Circle CI Status\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/jarun/bcal/actions\"\u003e\u003cimg src=\"https://github.com/jarun/bcal/actions/workflows/ci.yml/badge.svg?branch=master\" alt=\"GitHub CI Status\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://scan.coverity.com/projects/jarun-bcal\"\u003e\u003cimg src=\"https://img.shields.io/coverity/scan/17148.svg\" alt=\"Coverity Scan Build Status\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/jarun/bcal/blob/master/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/badge/license-GPLv3-yellowgreen.svg?maxAge=2592000\" alt=\"License\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://asciinema.org/a/168719\"\u003e\u003cimg src=\"https://asciinema.org/a/168719.svg\" alt=\"bcal_asciicast\" width=\"600\"/\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n`bcal` (*Byte CALculator*) is a REPL CLI utility for storage expression (e.g. `\"(2GiB * 2) / (2KiB \u003e\u003e 2)\"`) evaluation, SI/IEC conversion, byte address calculation, base conversion and LBA/CHS calculation. It's very useful for those who deal with bits, bytes, addresses and binary prefixes frequently.\n\nIt includes a built-in expression mode (`-b`) for general-purpose numerical calculations.\n\n`bcal` uses [SI and IEC binary prefixes](https://en.wikipedia.org/wiki/Binary_prefix) and supports 64-bit Operating Systems only.\n\n### Table of Contents\n\n- [Features](#features)\n- [Installation](#installation)\n  - [Dependencies](#dependencies)\n  - [From a package manager](#from-a-package-manager)\n  - [From source](#from-source)\n  - [make options](#make-options)\n  - [Termux](#termux)\n- [Usage](#usage)\n  - [cmdline options](#cmdline-options)\n  - [Operational notes](#operational-notes)\n- [Examples](#examples)\n- [Testing](#testing)\n- [Copyright](#copyright)\n\n### Features\n\n- REPL and single execution modes\n- evaluate arithmetic expressions involving storage units\n- perform general purpose calculations (built-in expression mode)\n  - arithmetic: addition, subtraction, multiplication, division, modulo\n  - bitwise: AND (\u0026), OR (|), XOR (^), complement (~), lshift (\u003c\u003c), rshift (\u003e\u003e)\n  - functions: exp(n), log(base, n), ln(n) [natural log], pow(n, exponent), root(radical, n)\n- works with piped input or file redirection\n- convert to IEC/SI standard data storage units\n- interactive mode with the last valid result stored for reuse\n- show the address in bytes\n- show address as LBA:OFFSET\n- convert CHS to LBA and *vice versa*\n- base conversion to binary, decimal and hex\n- show bit positions with bit value of a number\n- custom sector size, max heads/cylinder and max sectors/track\n- minimal dependencies\n\n### Installation\n\n#### Dependencies\n\n`bcal` is written in C and depends on standard libc and GNU Readline (or [BSD Editline](https://www.thrysoee.dk/editline/)). However, readline can be excluded by building with `O_NORL=1`, which uses a native input prompt with history file support instead.\n\n#### From a package manager\n\nInstall `bcal` from your package manager. If the version available is dated try an alternative installation method.\n\n\u003cdetails\u003e\u003csummary\u003ePackaging status (expand)\u003c/summary\u003e\n\u003cp\u003e\n\u003cbr\u003e\n\u003ca href=\"https://repology.org/project/bcal/versions\"\u003e\u003cimg src=\"https://repology.org/badge/vertical-allrepos/bcal.svg\" alt=\"Packaging status\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003c/details\u003e\n\n#### From source\n\nIf you have git installed, clone this repository. Otherwise, download the [latest stable release](https://github.com/jarun/bcal/releases/latest) or [development version](https://github.com/jarun/bcal/archive/master.zip) (*risky*).\n\nInstall to default location (`/usr/local`):\n\n    $ sudo make strip install\nTo link to libedit:\n\n    $ sudo make O_EL=1 strip install\nTo build without readline dependency (uses native input with history file support):\n\n    $ sudo make O_NORL=1 strip install\nTo uninstall, run:\n\n    $ sudo make uninstall\n\n`PREFIX` is supported, in case you want to install to a different location.\n\n##### make options\n\n- `O_NORL=1`: build without GNU Readline (native prompt with history file support).\n- `O_EL=1`: link against BSD Editline instead of Readline.\n- `O_STATIC=1`: build a static binary (forces `O_NORL=1`).\n- `strip`: target to strip the resulting binary after build.\n- `static`: target to build a static binary via `O_STATIC=1`.\n\nTo build with musl libc, use `musl-gcc` as the compiler, for example:\n\n       $ CC=musl-gcc make\n       $ CC=musl-gcc make O_STATIC=1\n\n#### Termux\n\n`bcal` can be compiled and installed from source in the Termux environment on `aarch64` Android devices. Instructions:\n\n```\n$ wget https://github.com/jarun/bcal/archive/master.zip\n$ unzip bcal-master.zip\n$ cd bcal-master/\n$ pkg install make clang readline-dev\n$ make strip install\n```\n\n### Usage\n\n#### cmdline options\n\n```\nusage: bcal [-b [expr]] [-c N] [-p N] [-f loc]\n            [-s bytes] [expr] [N [unit]] [-m] [-d] [-h]\n\nStorage expression calculator.\n\npositional arguments:\n expr       expression in decimal/hex operands\n N [unit]   capacity in B/KiB/MiB/GiB/TiB/kB/MB/GB/TB\n            https://en.wikipedia.org/wiki/Binary_prefix\n            default unit is B (byte), case is ignored\n            N can be decimal or '0x' prefixed hex value\n\noptional arguments:\n -b [expr]  enter expression mode or evaluate expression\n -c N       show +ve integer N in binary, decimal, hex\n -p N       show bit position (reversed if set) and value\n -f loc     convert CHS to LBA or LBA to CHS\n            refer to the operational notes in man page\n -s bytes   sector size [default 512]\n -m         show minimal output (e.g. decimal bytes)\n -d         enable debug information and logs\n -h         show this help\n\nprompt keys:\n b          toggle expression mode\n r          show result from last operation\n s          show sizes of storage types\n ?          show prompt help\n q/double ↵ quit program\n```\n\n#### Operational notes\n\n- **Interactive mode**: `bcal` enters the REPL mode if no arguments are provided. Storage unit conversion, base conversion and expression evaluation are supported in this mode. The last valid result is stored in the variable **r**.\n- **Expression**: Expression passed as argument in one-shot mode must be within double quotes. Inner spaces are ignored. Supported operators: `+`, `-`, `*`, `/`, `%` and C bitwise operators (except `~` due to storage width dependency).\n- **N [unit]**: `N` can be a decimal or '0x' prefixed hex value. `unit` can be B/KiB/MiB/GiB/TiB/kB/MB/GB/TB. Default is Byte. As all of these tokens are unique, `unit` is case-insensitive.\n- **Numeric representation**: Decimal and hex are recognized in expressions and unit conversions. Binary is also recognized in other operations.\n- **Syntax**: Prefix hex inputs with `0x`, binary inputs with `0b`.\n- **Precision**: 128 bits if `__uint128_t` is available or 64 bits for numerical conversions. Floating point operations use `long double`. Negative values in storage expressions are unsupported. Only 64-bit operating systems are supported.\n- **Fractional bytes do not exist** because they can't be addressed. `bcal` shows the floor value of non-integer _bytes_.\n- **CHS and LBA syntax**:\n  - LBA: `lLBA-MAX_HEAD-MAX_SECTOR`   [NOTE: LBA starts with `l` (case ignored)]\n  - CHS: `cC-H-S-MAX_HEAD-MAX_SECTOR` [NOTE: CHS starts with `c` (case ignored)]\n  - Format conversion arguments must be hyphen separated.\n  - Any unspecified value, including the one preceding the first `-` to the one following the last `-`, is considered `0` (zero).\n  - Examples:\n    - `c-50--0x12-` -\u003e C = 0, H = 50, S = 0, MH = 0x12, MS = 0\n    - `l50-0x12` -\u003e LBA = 50, MH = 0x12, MS = 0\n- **Default values**:\n  - sector size: 0x200 (512)\n  - max heads per cylinder: 0x10 (16)\n  - max sectors per track: 0x3f (63)\n- **Expression mode**: `r` is synced and can be used in expressions. The built-in evaluator uses `long double` arithmetic.\n\n### Examples\n\n1. Evaluate arithmetic expression of storage units.\n\n       $ bcal \"(5kb+2mb)/3\"\n       $ bcal \"5 tb / 12\"\n       $ bcal \"2.5mb*3\"\n       $ bcal \"(2giB * 2) / (2kib \u003e\u003e 2)\"\n2. Convert storage capacity to other units and get address, LBA.\n\n       $ bcal 20140115 b\n       $ bcal 0x1335053 B\n       $ bcal 0xaabbcc kb\n       $ bcal 0xdef Gib\n    Note that the units are case-insensitive.\n3. Convert storage capacity, set sector size to 4096 to calculate LBA.\n\n       $ bcal 0xaabbcc kb -s 4096\n4. Convert LBA to CHS.\n\n       $ bcal -f l500\n       $ bcal -f l0x600-18-0x7e\n       $ bcal -f l0x300-0x12-0x7e\n5. Convert CHS to LBA.\n\n       $ bcal -f c10-10-10\n       $ bcal -f c0x10-0x10-0x10\n       $ bcal -f c0x10-10-2-0x12\n       $ bcal -f c-10-2-0x12\n       $ bcal -f c0x10-10--0x12\n6. Show binary, decimal and hex representations of a number.\n\n       $ bcal -c 20140115\n       $ bcal -c 0b1001100110101000001010011\n       $ bcal -c 0x1335053\n       bcal\u003e c 20140115  // Interactive mode\n7. Perform bitwise operations.\n\n       $ bcal -b '0xFF \u0026 0x0F'\n       $ bcal -b '0x0F | 0xF0'\n       $ bcal -b '0xFF ^ 0xF0'\n       $ bcal -b '0xF0'\n       $ bcal -b '0x01 \u003c\u003c 3'\n       $ bcal -b '0x10 \u003e\u003e 2'\n       $ bcal -b '(0xFF \u0026 0x0F) | (0x0F \u003c\u003c 4)'\n8. Use expression mode.\n\n       $ bcal -b '3.5 * 2.1 + 5.7'\n       bcal\u003e b  // Interactive mode\n       expr\u003e 3.5 * 2.1 + 5.7\n9. Pipe input.\n\n       $ printf '15 kib + 15 gib \\n r / 5' | bcal -m\n       $ printf '15 + 15 + 2' | bcal -bm\n10. Redirect from file.\n\n        $ cat expr\n        15 gib + 15 kib\n        r / 5\n        $ bcal -m \u003c expr\n11. Use as a general-purpose calculator.\n\n        $ bcal -b\n12. Use mathematical functions.\n\n        $ bcal -b 'root(2, 17.3)'  // square root of 17.3\n        $ bcal -b 'exp(5.2)'\n        $ bcal -b 'pow(2, 8)'\n        $ bcal -b 'pow(10, 3) + root(2, 9)'\n13. Show bit positions with values.\n\n\u003cimg width=\"1033\" height=\"138\" alt=\"bcal bit position\" src=\"https://github.com/user-attachments/assets/1b4a6c5e-8b3f-4d4b-a4dd-9045689f7dd8\" /\u003e\n\n\n### Testing\n\nDue to the nature of the project, it's extremely important to test existing functionality before raising any PR. `bcal` has several test cases written in [`test.py`](test.py). To execute the test cases locally, install `pytest` and run:\n\n    $ make\n    $ python3 -m pytest test.py\n\n### Copyright\n\nCopyright © 2016 [Arun Prakash Jana](https://github.com/jarun)\n","funding_links":["https://github.com/sponsors/jarun"],"categories":["\u003ca name=\"calc\"\u003e\u003c/a\u003eCalculators","C","Development","Tools and Plugins","Applications","\\*nix/\\*nux","For Developers"],"sub_categories":["Chat","Windows","Productivity","Developer","Games","Directory Navigation"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjarun%2Fbcal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjarun%2Fbcal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjarun%2Fbcal/lists"}