File | Date | Author | Commit |
---|---|---|---|
inc | 2017-06-18 |
![]() |
[dfda6d] Align structure Data |
redhat | 2016-10-17 |
![]() |
[c61f1c] RPM version should start with a "v" |
src | 2017-07-30 |
![]() |
[b97ec4] Specify positive integer in conversion help |
.gitignore | 2017-06-16 |
![]() |
[2ed997] Logging framework |
.travis.yml | 2017-07-12 |
![]() |
[aa0269] Update fedora build to version 26 (#14) |
CHANGELOG | 2017-06-30 |
![]() |
[181625] Prepare for release v1.6 |
LICENSE | 2016-09-21 |
![]() |
[816bde] Initial commit |
Makefile | 2017-06-17 |
![]() |
[498e63] Add Python 3 test script |
README.md | 2017-07-30 |
![]() |
[b97ec4] Specify positive integer in conversion help |
bcal.1 | 2017-07-30 |
![]() |
[b97ec4] Specify positive integer in conversion help |
build-docker | 2016-10-17 |
![]() |
[18589d] Try a build inside docker |
test.py | 2017-06-24 |
![]() |
[87b64e] Check for malformed strings |
bcal
(Byte CALculator) is a command-line utility for storage conversions and calculations. Storage, hardware and firmware developers work with numerical calculations regularly e.g., storage unit conversions, address calculations etc. If you are one and can't calculate the hex address offset for (512 - 16) MiB immediately, or the value when the 43rd bit of a 64-bit address is set, bcal
is for you.
Though it started with storage, the scope of bcal
isn't limited to the storage domain. Feel free to raise PRs to simplify other domain-specific numerical calculations so it can evolve into an engineer's utility.
bcal
follows Ubuntu's standard unit conversion and notation policy. Only 64-bit operating systems are supported.
bcal
is written in C and depends on standard libc and GCC libquadmath.
bcal
is also available on
- AUR
- Debian Sid
- Ubuntu
- Ubuntu PPA
If you are on Fedora 24 or CentOS 7, visit the latest stable release and download the .rpm
package for your OS.
If you have git installed, clone this repository. Otherwise, download the latest stable release or development version (risky).
In the source directory, run:
$ make
$ sudo make install
To uninstall, run:
$ sudo make uninstall
usage: bcal [-c N] [-f FORMAT] [-s bytes] [-d] [-h]
[expression] [N unit]
Perform storage conversions and calculations.
positional arguments:
expression evaluate storage arithmetic expression
+, -, *, / with decimal inputs supported
unit can be multiplied or divided by +ve integers
units can be added or subtracted from each other
Examples:
bcal "(5kb+2mb)/3"
bcal "5 tb / 12"
bcal "2.5mb*3"
N [unit] capacity in B/KiB/MiB/GiB/TiB/kB/MB/GB/TB
see https://wiki.ubuntu.com/UnitsPolicy
default unit is B (byte), case is ignored
N can be decimal or '0x' prefixed hex value
optional arguments:
-c N show +ve integer N in binary, decimal and hex
-f FORMAT convert CHS to LBA or LBA to CHS
formats are hyphen-separated
LBA format:
starts with 'l':
lLBA-MAX_HEAD-MAX_SECTOR
CHS format:
starts with 'c':
cC-H-S-MAX_HEAD-MAX_SECTOR
omitted values are considered 0
FORMAT 'c-50--0x12-' denotes:
C = 0, H = 50, S = 0, MH = 0x12, MS = 0
FORMAT 'l50-0x12' denotes:
LBA = 50, MH = 0x12, MS = 0
default MAX_HEAD: 16, default MAX_SECTOR: 63
-s bytes sector size [default 512]
-m show minimal output (e.g. decimal bytes)
-d enable debug information and logs
-h show this help and exit
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 case-insensitive.0x
, binary inputs with 0b
, octal inputs with 00
.unsigned long long
and double
.bcal
shows the floor value of non-integer bytes.lLBA-MAX_HEAD-MAX_SECTOR
[NOTE: LBA starts with l
(case ignored)]cC-H-S-MAX_HEAD-MAX_SECTOR
[NOTE: CHS starts with c
(case ignored)]-
to the one following the last -
, is considered 0
(zero).$ bcal "(5kb+2mb)/3"
$ bcal "5 tb / 12"
$ bcal "2.5mb*3"
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
7. Help and additional information.
$ man bcal
$ bcal -h
Copyright © 2016-2017 Arun Prakash Jana