While you can always factor out declarations for
[io]base= based on the current input radix, another thing you might do is use the explicit hex notation, which should work regardless of input base. Like this:
printf %s\\n ibase=2 obase=F 1001 | bc
You might find this can be especially useful if you ever get lost when setting input bases, because you can always get back to a simple base 10 as easily as:
This is standardized syntax as mandated by POSIX:
- When either
obase is assigned a single digit value from the list in Lexical Conventions in
bc, the value shall be assumed in hexadecimal. (For example,
ibase=A sets to base ten, regardless of the current
ibase value.) Otherwise, the behavior is undefined when digits greater than or equal to the value of
ibase appear in the input. Both
obase shall have initial values of 10.
This is a historical convention which began with
dc (for which, on some systems,
bc is still little more than a front-end) and so...
echo 2i Fo 1001p|dc