Man page - bcal(1)
Packages contains this manual
Manual
BCAL
NAMESYNOPSIS
DESCRIPTION
FEATURES
OPERATIONAL NOTES
OPTIONS
PROMPT KEYS
EXAMPLES
AUTHORS
HOME
REPORTING BUGS
LICENSE
NAME
bcal - Storage expression calculator.
SYNOPSIS
bcal [-c N] [-f loc] [-s bytes] [expr] [N [unit]] [-b [expr]] [-m] [-d] [-h]
DESCRIPTION
bcal (Byte CALculator) is a command-line utility to help with numerical calculations and expressions involving binary prefixes, SI/IEC conversion, byte addressing, base conversion, LBA/CHS calculation etc.
It invokes GNU bc for non-storage expressions. Alternatively, it can also invoke calc ( http://www.isthe.com/chongo/tech/comp/calc/ ). To use calc :
export BCAL_USE_CALC=1
bcal uses [SI and IEC binary prefixes]: https://en.wikipedia.org/wiki/Binary_prefix
FEATURES
* evaluate
arithmetic expressions involving storage units
* perform general purpose calculations (using bc or calc)
* works with piped input or file redirection
* convert to IEC/SI standard data storage units
* interactive 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
* custom sector size, max heads/cylinder and max
sectors/track
* minimal dependencies
OPERATIONAL NOTES
|
1. |
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 . |
||
|
2. |
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). |
||
|
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. Default is Byte. As all of these tokens are unique, unit is case-insensitive. |
||
|
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 values in storage expressions are unsupported. Only 64-bit operating systems are supported. |
||
|
7. |
Fractional bytes do not exist , because they canβt be addressed. bcal shows the floor value of non-integer bytes . |
||
|
8. |
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
|
9. |
Default values : |
- sector size: 0x200 (512)
- max heads per cylinder: 0x10 (16)
- max sectors per track: 0x3f (63)
|
10. |
bc variables : scale = 10, ibase = 10. r is synced and can be used in expressions. bc is not called in minimal output mode. To use calc instead of bc , export BCAL_USE_CALC=1 . |
OPTIONS
|
-c= N |
Show decimal, binary and hex representation of positive integer N . |
||
|
-f= loc |
Convert CHS to LBA or LBA to CHS. loc is hyphen-separated representation of LBA or CHS. Please refer to the Operational Notes section for more details. |
-s= bytes
Sector size in bytes. Default value is 512.
-b= [expr]
Start in bc mode. If expression is provided, evaluate in bc and quit.
|
-m |
Show minimal output (e.g. decimal bytes). |
|||
|
-d |
Enable debug information and logs. |
|||
|
-h |
Show program help, storage sizes on the system and exit. |
PROMPT KEYS
|
b |
Toggle bc mode. |
|||
|
r |
Show result from last operation. |
|||
|
s |
Show sizes of storage types. |
|||
|
? |
Show prompt help. |
q, double Enter
Quit the program.
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)"
|
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 case-insensitive.
|
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 l0x600-18-0x7e
$ bcal -f l0x300-0x12-0x7e
|
5. |
Convert CHS to LBA. |
$ bcal -f
c10-10-10
$ bcal -f c0x10-0x10-0x10
$ bcal -f c0x10-10-2-0x12
$ bcal -f c-10-2-0x12
$ bcal -f c0x10-10--0x12
|
6. |
Show binary, decimal and hex representations of a number. |
$ bcal -c
20140115
$ bcal -c 0b1001100110101000001010011
$ bcal -c 0x1335053
bcal> c 20140115 // Interactive mode
|
7. |
Invoke bc . |
$ bcal -b
β3.5 * 2.1 + 5.7β
bcal> b // Interactive mode
bc vars: scale = 10, ibase = 10, last = r
bc> 3.5 * 2.1 + 5.7
|
8. |
Pipe input. |
$ printf
β15 kib + 15 gib \n r / 5β | bcal -m
$ printf β15 + 15 + 2β | bcal -bm
|
9. |
Redirect from file. |
$ cat expr
15 gib + 15 kib
r / 5
$ bcal -m < expr
|
10. |
Use as a general-purpose calculator. |
$ bcal -b
AUTHORS
Arun Prakash Jana <engineerarun@gmail.com>
HOME
https://github.com/jarun/bcal
REPORTING BUGS
https://github.com/jarun/bcal/issues
LICENSE
Copyright Β© 2016 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.