MPE/iX Shell and Utilities Reference Manual, Vol 1

bc(1) MPE/iX Shell and Utilities bc(1)
There is also a function scale() which can determine the scale of any expression. For
example,
scale(1.1234)
returns the result four, which is the scale of the number 1.1234. The result of the scale()
function is always an integer (that is, it has a scale of 0).
The maximum value for scale is given by the configuration variable {BC_SCALE_MAX}
and the minimum value is 0.
Bases
bc lets you specify numbers in different bases, for example, octal (base 8) or hexadecimal
(base 16). You can input numbers in one base and output them in a different base, simplifying
the job of converting from one base to another. bc does this using the built-in variables
ibase and obase
ibase is the base for input numbers. It has an initial value of 10 (normal decimal numbers).
To use a different base for inputting numbers, assign an integer to ibase,asin
ibase = 8
This says that all future input numbers will be in base 8 (octal). The largest valid input base is
16 and the smallest valid input base is 2. Since there is no mechanism provided to represent
digits larger than 15, bases larger than 16 are essentially useless. When the base is greater
than 10, use the uppercase letters as digits. For example, base 16 uses the digits 0 through 9,
and A through F. The digits are allowed in any number, regardless of the setting of ibase
but are largely meaningless if the base is smaller than the digit. The one case where this is
useful is in resetting the input base to 10. The constant A always has the value 10 no matter
what ibase is set to, so to reset the input base to 10, type
ibase = A
obase is the base in which numbers are output. It has an initial value of 10 (normal decimal
numbers). To change output bases, assign an appropriate integer to obase.
If the output base is 16 or less, bc displays numbers with normal digits and hexadecimal digits
(if needed). The output base can also be greater than 16, in which case each digit is displayed
as a decimal value and digits are separated by a single space. For example, if obase is 1000,
the decimal number 123456789 is displayed as
123 456 789
Here, the digits are decimal values from 0 through 999. As a result, all output values are bro-
ken up into one or more chunks with three digits per chunk. Using output bases that are large
powers of 10, you can columnate your output; for example, many users find that 100000
makes a good output base because numbers are grouped into chunks of five digits each.
1-48 Commands and Utilities