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. It invokes GNU bc for non-storage expressions.
16
17       bcal follows Ubuntu's standard unit conversion and notation policy:
18       https://wiki.ubuntu.com/UnitsPolicy
19

FEATURES

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

OPERATIONAL NOTES

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

OPTIONS

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

PROMPT KEYS

104       b      Toggle bc mode.
105
106       r      Show result from last operation.
107
108       s      Show sizes of storage types.
109
110       ?      Show prompt help.
111
112       q, double Enter
113              Quit the program.
114

EXAMPLES

116       1.  Evaluate arithmetic expression of storage units
117
118              $ bcal "(5kb+2mb)/3"
119              $ bcal "5 tb / 12"
120              $ bcal "2.5mb*3"
121              $ bcal "(2giB * 2) / (2kib >> 2)"
122
123       2.  Convert storage capacity to other units and get address, LBA.
124
125              $ bcal 20140115 b
126              $ bcal 0x1335053 B
127              $ bcal 0xaabbcc kb
128              $ bcal 0xdef Gib
129              Note that the units are case-insensitive.
130
131       3.  Convert storage capacity, set sector size to 4096 to calculate LBA.
132
133              $ bcal 0xaabbcc kb -s 4096
134
135       4.  Convert LBA to CHS.
136
137              $ bcal -f l500
138              $ bcal -f l0x600-18-0x7e
139              $ bcal -f l0x300-0x12-0x7e
140
141       5.  Convert CHS to LBA.
142
143              $ bcal -f c10-10-10
144              $ bcal -f c0x10-0x10-0x10
145              $ bcal -f c0x10-10-2-0x12
146              $ bcal -f c-10-2-0x12
147              $ bcal -f c0x10-10--0x12
148
149       6.  Show binary, decimal and hex representations of a number.
150
151              $ bcal -c 20140115
152              $ bcal -c 0b1001100110101000001010011
153              $ bcal -c 0x1335053
154              bcal> c 20140115 // Interactive mode
155
156       7.  Invoke bc.
157
158              $ bcal -b '3.5 * 2.1 + 5.7'
159              bcal> b // Interactive mode
160              bc vars: scale = 10, ibase = 10, last = r
161              bc> 3.5 * 2.1 + 5.7
162

AUTHORS

164       Arun Prakash Jana <engineerarun@gmail.com>
165

HOME

167       https://github.com/jarun/bcal
168

REPORTING BUGS

170       https://github.com/jarun/bcal/issues
171

LICENSE

173       Copyright © 2016 Arun Prakash Jana <engineerarun@gmail.com>
174
175       License      GPLv3+:     GNU     GPL     version     3     or     later
176       <http://gnu.org/licenses/gpl.html>.
177       This is free software: you are free  to  change  and  redistribute  it.
178       There is NO WARRANTY, to the extent permitted by law.
179
180
181
182Version 2.1                       11 Dec 2018                          BCAL(1)
Impressum