jarun/bcal — 697★ trên GitHub (C). :1234: Bits, bytes and general-purpose calculator
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
bcal (Byte CALculator) is a REPL CLI utility for storage expression (e.g. "(2GiB * 2) / (2KiB >> 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.
It also supports general-purpose operations (program option -b, prompt key b).
bcal uses SI and IEC binary prefixes and supports 64-bit Operating Systems only.
Table of Contents
Features
Installation
Dependencies
From a package manager
From source
make options
Termux
Usage
cmdline options
Operational notes
Environment variables
Examples
Testing
Copyright
Features
REPL and single execution modes
evaluate arithmetic expressions involving storage units
REPL mode with the last valid result stored for reuse
show the address in bytes
show address as LBA:OFFSET
convert CHS to LBA and vice versa
base conversion to binary, decimal and hex
show bit positions with bit value of a number
custom sector size, max heads/cylinder and max sectors/track
minimal dependencies
Installation
Dependencies
bcal is written in C and depends on standard libc and GNU Readline (or BSD Editline). However, readline can be excluded by building with O_NORL=1, which uses a native input prompt with history file support instead.
From a package manager
Install bcal from your package manager. If the version available is dated try an alternative installation method.
Packaging status (expand)
From source
If you have git installed, clone this repository. Otherwise, download the latest stable release or development version (risky).
Install to default location (/usr/local):
$ sudo make strip install
To link to libedit:
$ sudo make O_EL=1 strip install
To build without readline dependency (uses native input with history file support):
$ sudo make O_NORL=1 strip install
To uninstall, run:
$ sudo make uninstall
PREFIX is supported, in case you want to install to a different location.
make options
O_NORL=1: build without GNU Readline (native prompt with history file support).
O_EL=1: link against BSD Editline instead of Readline.
O_STATIC=1: build a static binary (forces O_NORL=1).
strip: target to strip the resulting binary after build.
static: target to build a static binary via O_STATIC=1.
To build with musl libc, use musl-gcc as the compiler, for example:
$ CC=musl-gcc make
$ CC=musl-gcc make O_STATIC=1
Termux
bcal can be compiled and installed from source in the Termux environment on aarch64 Android devices. Instructions:
$ wget https://github.com/jarun/bcal/archive/master.zip
$ unzip bcal-master.zip
$ cd bcal-master/
$ pkg install make clang readline-dev
$ make strip install
Usage
cmdline options
usage: bcal [-b [expr]] [-c N] [-p N] [-f loc]
[-s bytes] [expr] [N [unit]] [-m] [-H] [-d] [-h]
Bits, bytes and general-purpose calculator.
positional arguments:
expr expression in decimal/hex operands
N [unit] capacity in B/KiB/MiB/GiB/TiB/kB/MB/GB/TB
https://en.wikipedia.org/wiki/Binary_prefix
default unit is B (byte), case is ignored
N can be decimal or '0x' prefixed hex value
optional arguments:
-b [expr] start in general-purpose REPL mode
or, evaluate expression and quit
-c N show +ve integer N in binary, decimal, hex
-p N show bit position with bit value for N
-f loc convert CHS to LBA or LBA to CHS
refer to the operational notes in man page
-s bytes sector size [default 512]
-m show minimal output (e.g. decimal bytes)
-H show integral maths results in hex
-d enable debug information and logs
-h show this help
prompt keys:
b toggle general-purpose mode
c N show +ve integer N in binary, decimal, hex
p N show bit position with bit value for N
r show result from last operation
s show sizes of storage types
? show prompt help
q/double ↵ quit program
prompt: bytes> for storage mode, maths> for general-purpose mode
Operational notes
REPL 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.
Expression: Expression passed as argument in single execution mode must be quoted. Inner spaces are ignored. Operators supported in storage expressions: +, -, *, /, %.
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.
Numeric representation: Decimal and hex are recognized in expressions and unit conversions. Binary is also recognized in other operations.
Syntax: Prefix hex inputs with 0x, binary inputs with 0b.
Precision: 128 bits if __uint128_t is available or 64 bits for numeric conversions. Floating point operations use long double. Negative values in storage expressions are unsupported. Only 64-bit operating systems are supported.
Fractional bytes do not exist because they can't be addressed. bcal shows the floor value of non-integer bytes.
CHS and LBA syntax:
LBA: lLBA-MAX_HEAD-MAX_SECTOR [NOTE: LBA starts with l (case ignored)]
CHS: cC-H-S-MAX_HEAD-MAX_SECTOR [NOTE: CHS starts with c (case ignored)]
Format conversion arguments must be hyphen separated.
Any unspecified value, including the one preceding the first - to the one following the last -, is considered 0 (zero).
Examples:
c-50--0x12- -> C = 0, H = 50, S = 0, MH = 0x12, MS = 0
l50-0x12 -> LBA = 50, MH = 0x12, MS = 0
Default values:
sector size: 0x200 (512)
max heads per cylinder: 0x10 (16)
max sectors per track: 0x3f (63)
REPL mode: r is synced and can be used in expressions. The built-in evaluator uses long double arithmetic.
History file: Stored at $XDG_CONFIG_HOME/bcal/history, or $HOME/.config/bcal/history if XDG_CONFIG_HOME is unset.
Environment variables
BCAL_BIT_ANSI_COLOR_CODE: ANSI escape code to colorize bit value 1 in -p output. Set to empty to disable coloring. Examples:
export BCAL_BIT_ANSI_COLOR_CODE=$'\033[1;92m' // ANSI 8-bit color code
export BCAL_BIT_ANSI_COLOR_CODE=$'\u001b[1;38;5;51m' // ANSI 256-bit color code
export BCAL_BIT_ANSI_COLOR_CODE='' // Disable coloring
Due 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. To execute the test cases locally, install pytest and run:
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/jarun/bcal là nguồn chính thức.
jarun/bcal có bao nhiêu sao?
jarun/bcal có 697 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/jarun/bcal. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.