L'impostazione ibasesignifica che è necessario impostare la obasestessa base. Spiegare i tuoi esempi mostrerà questo:
echo "ibase=F;obase=A;C0" | bc
Si imposta bcper considerare i numeri di input come rappresentato nella base 15 con "ibase = F". "obase = A" imposta i numeri di output su base 10, che è l'impostazione predefinita.
bc legge C0 come un numero di base 15: C = 12. 12 * 15 = 180.
echo "ibase=F;obase=10;C0" | bc
In questo, si imposta l'ingresso sulla base 15 e l'uscita su 10 - nella base 15, quindi la base di uscita è 15. L'ingresso C0 nella base 15 è l'output C0 nella base 15.
echo "ibase=16;obase=A;C0" | bc
Impostare l'ingresso sulla base 16, l'uscita sulla base 10 (A nella base 16 è 10 nella base 10).
C0 convertito in base 10 è: 12 * 16 = 192
La mia regola personale è di impostare prima obase, in modo da poter usare la base 10. Quindi impostare ibase, usando anche la base 10.
Nota che bcha un'eccezione ironica: ibase=Ae obase=Aimposta sempre input e output su base 10. Dalla bcpagina man:
Single digit numbers always have the value of the digit
regardless of the value of ibase.
Questo comportamento è sancito dalla specifica di bc: Dalla specifica OpenGroup 2004bc :
When either ibase or 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.
Ecco perché l' ibase=Fimpostazione ha cambiato la base di input in base 15 e perché ho raccomandato di impostare sempre la base utilizzando la base 10. Evitare di confondersi.