16.12.2012 Views

z/OS V1R9.0 UNIX System Services Command ... - Christian Grothoff

z/OS V1R9.0 UNIX System Services Command ... - Christian Grothoff

z/OS V1R9.0 UNIX System Services Command ... - Christian Grothoff

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

|<br />

|<br />

|<br />

|<br />

Bases<br />

The maximum value for scale is given by the configuration variable<br />

{BC_SCALE_MAX} and the minimum value is 0.<br />

bc lets you specify numbers in different bases—for example, octal (base 8) or<br />

hexadecimal (base 16). You can input numbers in one base and output them in a<br />

different base, simplifying the job of converting from one base to another. bc does<br />

this using the built-in variables ibase and obase.<br />

ibase is the base for input numbers. It has an initial value of 10 (normal decimal<br />

numbers). To use a different base for inputting numbers, assign an integer to ibase,<br />

as in:<br />

ibase = 8<br />

This means that all future input numbers are to be in base 8 (octal). The largest<br />

valid input base is 16, and the smallest valid input base is 2. There is no<br />

mechanism provided to represent digits larger than 15, so bases larger than 16 are<br />

essentially useless. When the base is greater than 10, use the uppercase letters as<br />

digits. For example, base 16 uses the digits 0 through 9, and A through F. The digits<br />

are allowed in any number, regardless of the setting of ibase but are largely<br />

meaningless if the base is smaller than the digit. The one case where this is useful<br />

is in resetting the input base to 10. The constant A always has the value 10 no<br />

matter what ibase is set to, so to reset the input base to 10, type:<br />

ibase = A<br />

obase is the base in which numbers are output. It has an initial value of 10 (normal<br />

decimal numbers). To change output bases, assign an appropriate integer to obase.<br />

If the output base is 16 or less, bc displays numbers with normal digits and<br />

hexadecimal digits (if needed). The output base can also be greater than 16, in<br />

which case each digit is printed as a decimal value and digits are separated by a<br />

single space. For example, if obase is 1000, the decimal number 123 456 789 is<br />

printed as:<br />

123 456 789<br />

Here, the digits are decimal values from 0 through 999. As a result, all output values<br />

are broken up into one or more chunks with three digits per chunk. Using output<br />

bases that are large powers of 10, you can arrange your output in columns; for<br />

example, many users find that 100 000 makes a good output base, because<br />

numbers are grouped into chunks of five digits each.<br />

Long numbers are output with a maximum of 70 characters per line. If a number is<br />

longer than this, bc puts a backslash (\) at the end of the line indicating that the<br />

number is continued on the next line. The backslash (\) and newline characters are<br />

counted as part of the 70 character length.<br />

Internal calculations are performed in decimal, regardless of the input and output<br />

bases. Therefore the number of places after the decimal point are dictated by the<br />

scale when numbers are expressed in decimal form.<br />

The maximum value for obase is given by the configuration variable<br />

{BC_BASE_MAX}.<br />

bc<br />

Chapter 2. Shell command descriptions 53

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!