Dc (computer Program) - Input/Output

Input/Output

To read a line from stdin, use the '?' command. This will evaluate the line as if it were a dc command, and so it is necessary that it be syntactically correct and potentially be a security problem since the '!' dc command will allow arbitrary command execution.

As mentioned above, 'p' will print the top of the stack with a newline after it. 'n' will pop the top of the stack and output it without a trailing newline. 'f' will dump the entire stack with one entry per line.

dc also support arbitrary input and output radices. The 'i' command will pop the top of the stack and use it for the input base. Hex digits must be in upper case to avoid collisions with dc commands and are not limited to A-F if the input radix is larger than 16. The 'o' command does the same for the output base, but keep in mind that the input base will affect the parsing of every numeric value afterwards so it is usually advisable to set the output base first. To read the values, the 'K', 'I' and 'O' will push the current precision, input radix and output radix on to the top of the stack.

As an example, to convert from hex to binary:

16i2o DEADBEEFp

outputs 11011110101011011011111011101111.

Read more about this topic:  Dc (computer Program)

Famous quotes containing the words input and/or output:

    Family life is not a computer program that runs on its own; it needs continual input from everyone.
    Neil Kurshan (20th century)

    Lizzie Borden took an axe
    And gave her mother forty whacks;
    When she saw what she had done,
    She gave her father forty-one.
    —Anonymous. Late 19th century ballad.

    The quatrain refers to the famous case of Lizzie Borden, tried for the murder of her father and stepmother on Aug. 4, 1892, in Fall River, Massachusetts. Though she was found innocent, there were many who contested the verdict, occasioning a prodigious output of articles and books, including, most recently, Frank Spiering’s Lizzie (1985)