Bc


From Linuxconfig.org

Jump to: navigation, search

.. 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
Image:bc01.gif

Very good. How about subtraction:

$ echo "34.7 - 345.655" | bc
Image:bc02.gif

Multiplication:

$ echo "34.7 * 345.655" | bc
Image:bc03.gif

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
Image:bc04.gif

The default precision is 0:

echo "10 / 3" | bc
Image:bc05.gif

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
Image:bc06.gif

.. back to the list of Linux Commands

Personal tools
Linux Commands