MPE/iX Shell and Utilities Reference Manual, Vol 1

dc(1) MPE/iX Shell and Utilities dc(1)
Numbers in Different Bases
Programmers often find it useful to perform arithmetic with numbers in bases other than ten,
for example, octal (base 8) or hexadecimal (base 16) numbers. Several commands help make
this possible.
I pushes the current input base onto the stack.
i pops the top value of the stack and uses this as the base when interpreting further
input. For example,
8i
tells dc that from now on, it is to interpret input numbers as octal values. For
example, if you type 10 as input, dc interprets it as an octal number, equal to 8 (base
ten).
Note: You can use the characters A through F to input hexadecimal digits regardless
of the base.
O pushes the current output base onto the stack.
o pops the top value of the stack and uses this as the base when printing output. For
example,
16o
tells dc to print subsequent numbers in hexadecimal format.
Note: The input and output bases can be different; for example, you may find this
convenient if you want to convert input in one base to output in another.
You can make the output base larger than 16. In this case, dc prints each digit as a decimal
value and separates them with a single space. For example,
1000 o
123456789 p
prints
123 456 789
This sets the output base to 1000, where digits are decimal values from 0 through 999. As a
result, dc breaks up all values into one or more chunks with three digits per chunk. Using
output bases that are large powers of ten, you can put your output in columns; for example,
many users find that 100000 makes a good output base because dc groups numbers into
chunks of five digits each.
1-160 Commands and Utilities