1BCAL(1)                          User Commands                         BCAL(1)
2
3
4

NAME

6       bcal - Storage expression calculator.
7

SYNOPSIS

9       bcal [-c N] [-f loc] [-s bytes] [expr] [N [unit]] [-b [expr]] [-m] [-d]
10       [-h]
11

DESCRIPTION

13       bcal (Byte CALculator) is a command-line utility to help with numerical
14       calculations  and expressions involving binary prefixes, SI/IEC conver‐
15       sion, byte addressing, base conversion, LBA/CHS calculation etc.
16
17       It invokes GNU bc for non-storage expressions.  Alternatively,  it  can
18       also  invoke calc (http://www.isthe.com/chongo/tech/comp/calc/). To use
19       calc:
20
21       export BCAL_USE_CALC=1
22
23       bcal      uses      [SI      and      IEC       binary       prefixes]:
24       https://en.wikipedia.org/wiki/Binary_prefix
25

FEATURES

27         * evaluate arithmetic expressions involving storage units
28         * perform general purpose calculations (using bc or calc)
29         * works with piped input or file redirection
30         * convert to IEC/SI standard data storage units
31         * interactive mode with the last valid result stored for reuse
32         * show the address in bytes
33         * show address as LBA:OFFSET
34         * convert CHS to LBA and vice versa
35         * base conversion to binary, decimal and hex
36         * custom sector size, max heads/cylinder and max sectors/track
37         * minimal dependencies
38

OPERATIONAL NOTES

40       1.  Interactive  mode:  bcal  enters  the REPL mode if no arguments are
41           provided. Storage unit conversion, base conversion  and  expression
42           evaluation  are  supported  in  this mode. The last valid result is
43           stored in the variable r.
44
45       2.  Expression: Expression passed as argument in one-shot mode must  be
46           within  double  quotes.  Inner spaces are ignored. Supported opera‐
47           tors: +, -, *, /, % and C bitwise operators (except ~ due to  stor‐
48           age width dependency).
49
50       3.  N  [unit]:  N can be a decimal or '0x' prefixed hex value. unit can
51           be B/KiB/MiB/GiB/TiB/kB/MB/GB/TB. Default is Byte. As all of  these
52           tokens are unique, unit is case-insensitive.
53
54       4.  Numeric  representation:  Decimal and hex are recognized in expres‐
55           sions and unit conversions. Binary is also recognized in other  op‐
56           erations.
57
58       5.  Syntax: Prefix hex inputs with '0x', binary inputs with '0b'.
59
60       6.  Precision:  128 bits if __uint128_t is available or 64 bits for nu‐
61           merical conversions. Floating point  operations  use  long  double.
62           Negative values in storage expressions are unsupported. Only 64-bit
63           operating systems are supported.
64
65       7.  Fractional bytes do not exist, because  they  can't  be  addressed.
66           bcal shows the floor value of non-integer bytes.
67
68       8.  CHS and LBA syntax:
69             -  LBA:  'lLBA-MAX_HEAD-MAX_SECTOR'    [NOTE: LBA starts with 'l'
70           (case ignored)]
71             - CHS: 'cC-H-S-MAX_HEAD-MAX_SECTOR' [NOTE: CHS  starts  with  'c'
72           (case ignored)]
73             - Format conversion arguments must be hyphen separated.
74             -  Any  unspecified  value, including the one preceding the first
75           '-' to the one following the last '-', is considered '0' (zero).
76             - Examples:
77               - 'c-50--0x12-' -> C = 0, H = 50, S = 0, MH = 0x12, MS = 0
78               - 'l50-0x12' -> LBA = 50, MH = 0x12, MS = 0
79
80       9.  Default values:
81             - sector size: 0x200 (512)
82             - max heads per cylinder: 0x10 (16)
83             - max sectors per track: 0x3f (63)
84
85       10. bc variables: scale = 10, ibase = 10. r is synced and can  be  used
86           in  expressions.  bc  is  not called in minimal output mode. To use
87           calc instead of bc, export BCAL_USE_CALC=1.
88

OPTIONS

90       -c=N   Show decimal, binary and hex representation of positive  integer
91              N.
92
93       -f=loc Convert CHS to LBA or LBA to CHS. loc is hyphen-separated repre‐
94              sentation of LBA or CHS. Please refer to the  Operational  Notes
95              section for more details.
96
97       -s=bytes
98              Sector size in bytes. Default value is 512.
99
100       -b=[expr]
101              Start  in bc mode. If expression is provided, evaluate in bc and
102              quit.
103
104       -m     Show minimal output (e.g. decimal bytes).
105
106       -d     Enable debug information and logs.
107
108       -h     Show program help, storage sizes on the system and exit.
109

PROMPT KEYS

111       b      Toggle bc mode.
112
113       r      Show result from last operation.
114
115       s      Show sizes of storage types.
116
117       ?      Show prompt help.
118
119       q, double Enter
120              Quit the program.
121

EXAMPLES

123       1.  Evaluate arithmetic expression of storage units
124
125              $ bcal "(5kb+2mb)/3"
126              $ bcal "5 tb / 12"
127              $ bcal "2.5mb*3"
128              $ bcal "(2giB * 2) / (2kib >> 2)"
129
130       2.  Convert storage capacity to other units and get address, LBA.
131
132              $ bcal 20140115 b
133              $ bcal 0x1335053 B
134              $ bcal 0xaabbcc kb
135              $ bcal 0xdef Gib
136              Note that the units are case-insensitive.
137
138       3.  Convert storage capacity, set sector size to 4096 to calculate LBA.
139
140              $ bcal 0xaabbcc kb -s 4096
141
142       4.  Convert LBA to CHS.
143
144              $ bcal -f l500
145              $ bcal -f l0x600-18-0x7e
146              $ bcal -f l0x300-0x12-0x7e
147
148       5.  Convert CHS to LBA.
149
150              $ bcal -f c10-10-10
151              $ bcal -f c0x10-0x10-0x10
152              $ bcal -f c0x10-10-2-0x12
153              $ bcal -f c-10-2-0x12
154              $ bcal -f c0x10-10--0x12
155
156       6.  Show binary, decimal and hex representations of a number.
157
158              $ bcal -c 20140115
159              $ bcal -c 0b1001100110101000001010011
160              $ bcal -c 0x1335053
161              bcal> c 20140115 // Interactive mode
162
163       7.  Invoke bc.
164
165              $ bcal -b '3.5 * 2.1 + 5.7'
166              bcal> b // Interactive mode
167              bc vars: scale = 10, ibase = 10, last = r
168              bc> 3.5 * 2.1 + 5.7
169
170       8.  Pipe input.
171
172              $ printf '15 kib + 15 gib \n r / 5' | bcal -m
173              $ printf '15 + 15 + 2' | bcal -bm
174
175       9.  Redirect from file.
176
177              $ cat expr
178              15 gib + 15 kib
179              r / 5
180              $ bcal -m < expr
181
182       10. Use as a general-purpose calculator.
183
184              $ bcal -b
185

AUTHORS

187       Arun Prakash Jana <engineerarun@gmail.com>
188

HOME

190       https://github.com/jarun/bcal
191

REPORTING BUGS

193       https://github.com/jarun/bcal/issues
194

LICENSE

196       Copyright © 2016 Arun Prakash Jana <engineerarun@gmail.com>
197
198       License  GPLv3+:  GNU  GPL  version  3  or  later   <http://gnu.org/li
199       censes/gpl.html>.
200       This  is  free  software:  you  are free to change and redistribute it.
201       There is NO WARRANTY, to the extent permitted by law.
202
203
204
205Version 2.4                       24 Jan 2022                          BCAL(1)
Impressum