Bc
|
From Linuxconfig.org
.. back to the list of Linux Commands
Name
bc - An arbitrary precision calculator language
Synopsis - man page
bc [ -hlwsqv ] [long-options] [ file ... ]
Examples
This is very handy calculator. No need for GUI calculator. Lets see if it knows how to count. Addition:
$ echo "34.7 + 345.655" | bc
Very good. How about subtraction:
$ echo "34.7 - 345.655" | bc
Multiplication:
$ echo "34.7 * 345.655" | bc
For division we need to specify floating point as a "scale=?" so for example calculate with floating point precision of 10 we can enter:
$ echo "scale=10; 10 / 3" | bc
The default precision is 0:
echo "10 / 3" | bc
Converting from decimal to hexadecimal is even easier, All we need to specify is output base ( obase ) and input base ( ibase ). Lets convert decimal 1000 to hexadecimal number:
$ echo "obase=16; ibase=10; 1000;" | bc














