Bc is both a programming language that supports arbitrary precision numbers and an arbitrary precision desktop calculator program (utility), which handles scripts and commands written in the language bc and interactively executes the statements from the user. This tool can be used to do some of the number theoretical calculations with higher speed and higher precision than within the number theory educational program.
The utility bc, an extended precision calculator, can compute to at least 99 places right of the decimal point and at least 4000 to the left.
A standard math library is available by command line option. If requested, the math library is defined before processing any files. bc starts by processing code from all the files listed on the command line in the order listed. After all files have been processed, bc reads from the standard input. All code is executed as it is read. (If a file contains a command to halt the processor, bc will never read from the standard input.)
Calling syntax:
bc [ -hlwsqv ] [long-options] [ files ]
BC and the Educational Software "Number Theory" Distributed with CrypTool
Part of the distribution of the educational tool "Number Theory" is the command line calculator, bc (version 1.06, published by Free Software Foundation under GPL), supplemented with some functions from some file loaded directly when starting bc from the educational tool.
Bc as Command Line Calculator
1) For whole numbers bc deals with multiple bases. The input base is stored in the environment variable ibase. Setting conversion bases means, bc inputs ALL numbers using ibase. The output base is stored in obase.
Sample: To convert 4521 from base 7 to base 13, you have to enter:
obase = 13
ibase = 7
4521
or another sample: Conversion from the decimal to the hexadecimal number system:
obase=16; ibase=10; 13
B
2) For fractional precision of the calculation bc deals with the environment variable scale, which means the precision of floating points, which is how many digits after the point. By default the scale is 0, that means it is integer. The result of division will usually be a floating point number. In order to get the correct answer, you need to specify the variable scale. scale means the precision of floating point. In "5.00500" the scale is 5; in "5.005" the scale is 3. Some implementations also output one digit more (see below).
Samples:
scale=6; 60/7.02
6.6476776
obase=10; ibase=10; scale=0; 7/3
2
obase=10; ibase=10; scale=3; 7/3
2.2523
3) To do calculation with bc there are three possibilities:
At the input mode of bc you can repeat the last statement using the vertical arrow keys on the keyboard, and then edit it.
To get the value of an environment variable: Just enter the name of the variable and enter.
Some Sample Calculations Using bc (Base Calculator)
You can call bc from within the educational program "Number Theory" via F3 (menu Calculators \ BC Calculator) or from the command prompt:
bc
Test calculation: 686^79:
686^79
117382982726682578986166177099458354591354816385525364361499835772376409385660129455427115381646910282753710610818762831176373701406457183724515147357457376424117782495278817923488619922286175976292059037752989068589810057216
quit
Description for further functions transferred via the educational program "Number Theory" are available within the educational program via F8 (menu Glossaries \ BC Functions).
powermod(17,33,11)
7
euklid(847,22)
11
Remark 1: BC as a Programming Language
bc is a programming language, which supports calculations (numeric processing) in an arbitrary precision. Its description is included in the POSIX P1003.2/D11 draft standard.
The syntax is similar to "C" – with the following (and more) exceptions:
Other features of the bc program are:
Remark 2: Links
http://directory.fsf.org/gnu/bc.html - Web page about the GNU package
http://www.gnu.org/software/bc/bc.html - Web page about BC
http://ftp.gnu.org/pub/gnu/bc/bc-1.06.tar.gz - Source code, released 2001
http://en.wikipedia.org/wiki/Bc_(Unix) - Wikipedia about bc
http://de.wikipedia.org/wiki/Basic_Calculator - Wikipedia about bc