feed-image  Delivered by FeedBurner  ISSN 1836-5930






Visitors Online

We have 52 guests online

Poll

Which of following tutorials would you like to see on the Linuxconfig.org?
 
Partner Linux Sites
TuxMachines
DebianAdmin
Monsterb
LinuxBloggers
AdamsInfo
LinuxScrew
FreeSoftwareLinux
Jam's Ubuntu Blog
All For Linux

bc
Article Index
1. Name
2. Synopsis
3. Examples

1. Name

bc[man page] - An arbitrary precision calculator language

2. Synopsis

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

3. 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 
bc calculator addition
Very good. 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 floating point as a "scale=?" so for example calculate with floating point precision of 10 we can 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 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 
bc convert from decimal to hexadecimal