Contents[Hide]

1. Name

bc[man page] - An arbitrary precision calculator language

2. Synopsis

bc [ -hlwsqv ] [long-options] [  file ... ] 

3. Examples

bc is a very handy calculator. No need for GUI when using bc. Let's see if it knows how to count. We will start with addition:

$ echo "34.7 + 345.655" | bc 

bc calculator addition
How about subtraction:

$ echo "34.7 - 345.655" | bc 

bc calculator subtraction
Multiplication:

$ echo "34.7 * 345.655" | bc 

bc calculator multiplication
For division we need to specify a floating point as a "scale=x", so for example to calculate with a floating point precision of 10, we should enter:

$ echo "scale=10; 10 / 3" | bc 

bc calculator division with floating point precision
The default precision is 0:

echo "10 / 3" | bc 

bc calculator division with no precision
Converting from decimal to hexadecimal number is even easier. All we need to specify is an output base ( obase ) and an input base ( ibase ). Let's convert a decimal 1000 number to a hexadecimal number:

$ echo "obase=16; ibase=10; 1000;" | bc 

bc convert from decimal to hexadecimal

Free Linux eBooks

Linux Technical Writer

LinuxCareer, Casual, Volunteer, Home Based

Do you wish to join Linuxcareer.com project and find out how to be a technical writer? We are now looking for volunteers to help us write tutorials and share them with Linux community

  • Casual work from home
  • 10 articles / year

Any active Linuxcareer.com’s author will be entitled to following benefits:

  • actively participate in Linuxcareer.com’s decision making process
  • feedback and help

APPLY

Do you have the right skills?

Our IT Skills Watch page reflects an up to date IT skills demand leaning towards the Linux and Unix environment. We have considered a number of skills and operating systems.

See the result...

Linux Online Training

Learn to run Linux servers and prepare for LPI certification with Linux Academy. 104 available video lessons with PDF course notes with your own server!

Go to top