Create a shell script named my-calculator.sh under ~/apps:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
Note: put obase BEFORE ibase, or the obase will based on ibase. For example, the result of
echo "ibase=16;obase=10;A+A" | bc
is 14, but not 20. After "ibase=16", the "10" in "obase=10" is actually a hex, not a decimal. To avoid interfered by ibase, we should always declare obase before ibase.
Now add "alias mc=/home/chad/apps/my-calculator.sh" into your ~/.zshrc, you can do hex calculation by:
$ mc ih oh A+A
Add hex numbers and output to decimal:
$ mc ih A+A
Convert a hex into decimal:
$ mc ih 23B
Convert a decimal to hex:
$ mc oh 23432
Some ordinary decimal calculation:
$ mc 234+345