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 data storage units, addressing,
15       base conversion 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/) which
19       works better with expressions involving multiple bases. To use calc:
20
21       export BCAL_USE_CALC=1
22
23       bcal follows Ubuntu's standard unit conversion and notation policy:
24       https://wiki.ubuntu.com/UnitsPolicy
25

FEATURES

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

OPERATIONAL NOTES

39       1.  Interactive mode: bcal enters the REPL mode  if  no  arguments  are
40           provided.  Storage  unit conversion, base conversion and expression
41           evaluation are supported in this mode. The  last  valid  result  is
42           stored in the variable r.
43
44       2.  Expression:  Expression passed as argument in one-shot mode must be
45           within double quotes. Inner spaces are  ignored.  Supported  opera‐
46           tors:  +, -, *, /, % and C bitwise operators (except ~ due to stor‐
47           age width dependency).
48
49       3.  N [unit]: N can be a decimal or '0x' prefixed hex value.  unit  can
50           be  B/KiB/MiB/GiB/TiB/kB/MB/GB/TB  following Ubuntu policy. Default
51           is byte. As all of these tokens are unique, unit  is  case-insensi‐
52           tive.
53
54       4.  Numeric  representation:  Decimal and hex are recognized in expres‐
55           sions and unit conversions. Binary  is  also  recognized  in  other
56           operations.
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
61           numerical 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

AUTHORS

171       Arun Prakash Jana <engineerarun@gmail.com>
172

HOME

174       https://github.com/jarun/bcal
175

REPORTING BUGS

177       https://github.com/jarun/bcal/issues
178

LICENSE

180       Copyright © 2016 Arun Prakash Jana <engineerarun@gmail.com>
181
182       License     GPLv3+:     GNU     GPL     version     3     or      later
183       <http://gnu.org/licenses/gpl.html>.
184       This  is  free  software:  you  are free to change and redistribute it.
185       There is NO WARRANTY, to the extent permitted by law.
186
187
188
189Version 2.2                       07 Jan 2020                          BCAL(1)
Impressum