feed-image  ISSN 1836-5930



Receive Your Complimentary Guide to Linux NOW!


A Newbie's Getting Started Guide to Linux

Linux from Scratch - Create Your Own Linux System - Free eBook

The GNU/Linux Advanced Administration

A Complete Beginner's Manual for Ubuntu 10.04 (Lucid Lynx)




Poll

Do you care about your privacy when using a FACEBOOK?
 

linuxconfig.org
is hosted by:



Partner Linux Sites
TuxMachines
DebianAdmin
Monsterb
LinuxBloggers
AdamsInfo
LinuxScrew
FreeSoftwareLinux
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