bc: inconsistent result
Using bc utility to convert between binary and decimals.
Code:
Decimal to binary: Why does order matter in one case, and not the other? Is there a utility that converts IP4 address (dot decimal notation) into "dot" binary outputs? Thank you. |
|
Quote:
From link above: "For multi-digit numbers, bc changes all input digits greater or equal to ibase to the value of ibase-1. " Here I an example where all the digits are less than ibase. Thus none of the input digits of obase or input values (011 or 0111) exceeded ibase's value. Thus there is no change to the input digits. But the answers are still incorrect. Code:
~ $ echo "ibase=2;obase=10;011" | bc |
You missed the line right above that one:
Quote:
Code:
$ echo "ibase=2;obase=10;011" | bc Code:
$ echo "ibase=2;obase=1010;011" | bc |
Thank you.
|
All times are GMT -5. The time now is 12:30 PM. |