bcal man page
bcal — Storage expression calculator.
Synopsis
bcal [c N] [f FORMAT] [s bytes] [m] [b] [d] [h]
[expression] [N [unit]]
Description
bcal (Byte CALculator) is a commandline utility to help with numerical calculations and expressions involving data storage units, addressing, base conversion etc.
Features
* evaluate arithmetic expressions involving storage units
* convert to IEC/SI standard data 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
* show binary, decimal and hex representation of a number
* custom sector size, max heads/cylinder and max sectors/track
* minimal dependencies
bcal follows Ubuntu's standard unit conversion and notation policy. Only 64bit operating systems are supported.
Refer to: https://wiki.ubuntu.com/UnitsPolicy
Operational Notes
 1.
REPL mode: bcal enters the REPL mode if no arguments are provided. Storage unit conversion and expression evaluation are supported in this mode. The last valid result is stored in the variable r.
 2.
Expression: An expression must be within double quotes. Inner spaces are ignored. A unit can be added to, subtracted from or divided by another unit. A unit can be multiplied or divided by positive integers.
 3.
N [unit]: N can be a decimal or '0x' prefixed hex value. unit can be B/KiB/MiB/GiB/TiB/kB/MB/GB/TB following Ubuntu policy. Default is byte. As all of these tokens are unique, unit is caseinsensitive.
 4.
Numeric representation: Decimal and hex are recognized in expressions and unit conversions. Binary is also recognized in other operations.
 5.
Syntax: Prefix hex inputs with '0x', binary inputs with '0b'.
 6.
Precision: 128 bits if __uint128_t is available or 64 bits for numerical conversions. Floating point operations use long double. Negative arguments are unsupported.
 7.
Fractional bytes do not exist, because they can't be addressed. bcal shows the floor value of noninteger bytes.
 8.
CHS and LBA syntax:
 LBA: 'lLBAMAX_HEADMAX_SECTOR' [NOTE: LBA starts with 'l' (case ignored)]
 CHS: 'cCHSMAX_HEADMAX_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). 9.
Default values:
 sector size: 0x200 (512)
 max heads per cylinder: 0x10 (16)
 max sectors per track: 0x3f (63) 10.
bc variables: scale = 5, ibase = 10. bc is not called in minimal output mode.
Options
 c=N
Show decimal, binary and hex representation of positive integer N.
 f=FORMAT

Convert CHS to LBA or LBA to CHS. FORMAT is hyphenseparated representation of LBA or CHS.
LBA: lLBAMAX_HEADMAX_SECTOR (starts with 'l')
CHS: cCHSMAX_HEADMAX_SECTOR (starts with 'c')Omitted values, (other than MAX_HEAD and MAX_SECTOR) are considered 0. Default MAX_HEAD: 16, default MAX_SECTOR: 63.
 s=bytes
Sector size in bytes. Default value is 512.
 m
Show minimal output (e.g. decimal bytes).
 b
Show sizes of basic data types on the system in bytes.
 d
Enable debug information and logs.
 h
Show program help and exit.
Examples
 1.
Evaluate arithmetic expression of storage units
$ bcal "(5kb+2mb)/3" $ bcal "5 tb / 12" $ bcal "2.5mb*3" $ bcal "(2giB * 2) / 2kib"
 2.
Convert storage capacity to other units and get address, LBA.
$ bcal 20140115 b $ bcal 0x1335053 B $ bcal 0xaabbcc kb $ bcal 0xdef Gib Note that the units are caseinsensitive.
 3.
Convert storage capacity, set sector size to 4096 to calculate LBA.
$ bcal 0xaabbcc kb s 4096
 4.
Convert LBA to CHS.
$ bcal f l500 $ bcal f l0x600180x7e $ bcal f l0x3000x120x7e
 5.
Convert CHS to LBA.
$ bcal f c101010 $ bcal f c0x100x100x10 $ bcal f c0x101020x12 $ bcal f c1020x12 $ bcal f c0x10100x12
 6.
Show binary, decimal and hex representations of a number.
$ bcal c 20140115 $ bcal c 0b1001100110101000001010011 $ bcal c 0x1335053
Authors
Arun Prakash Jana <engineerarun@gmail.com>
Home
Reporting Bugs
License
Copyright © 20162018 Arun Prakash Jana <engineerarun@gmail.com>
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.