I’m trying to change the input and the output base using dc in a shell script. I’m having trouble writing down the exact command. I do not have BASH.
I’ve tried variations on this: (input numb) 2i 10o p | dc
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
dcman page uses the term “radix”, not “base”; that might help you search for information.You have to set the input radix before giving it an input number. For example:
prints
100(decimal) because the radix was still set to the default 10 (decimal) whendcsaw the input value100.Try this:
The output is:
Note that
dcseems to require upper case for the hex digitsA..F. And you have to be careful with radix specifications; after you’ve done16ito set input to hexadecimal,10iinterprets10as a hexadecimal number and sets the input radix to 16 (and16itries to set it to 0x16 or 22, which is illegal).In fact, I see I ran into that problem myself. I meant to set the output radix to 16. I should have written
Ao p 2o prather than10o p 2o p. I’ll leave it as it is to illustrate the issue.