RSS Subscription
Linux Howtos & Tutorials

Enter your email:

Delivered by


NOTE:New tutorials are from LinuxCareer.com

Poll

Do you own or wish to have iPhone?
 


Linux eBooks FREE Download
A guide to programming Linux kernel modules
Introduction to Linux - A Hands on Guide
A Newbie's Getting Started Guide to Linux

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

Linux: The Hacking Solution (v.3.0)

SQLite 3 with PHP Essential Training – Free Video Training Tutorials

This guide will introduce you to the world of GNU/Linux

The GNU/Linux Advanced Administration

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

Advanced Bash-Scripting Guide

Set up, maintain, and secure a small office email server

Partner Linux Sites:
How-To.LinuxCareer.com
Jobs.LinuxCareer.com
TuxMachines
Monsterb
LinuxBloggers
AdamsInfo
LinuxScrew
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

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

Share this linux post:

Submit bc in Delicious Submit bc in Digg Submit bc in FaceBook Submit bc in Google Bookmarks Submit bc in Stumbleupon Submit bc in Technorati Submit bc in Twitter
 
Comments for this page are closed !!!
Please visit our new Linux Forum for additional help or discussion.


Linux eBooks FREE Download