0

I recently read about bc and found that it supports obase upto 999. Can anyone point me to the numeral set for bc for base greater than 16.

3
  • 3
    the decimals from 0 to ($base minus one)? echo "obase=20; 20" | bc, echo "obase=20; 39" | bc, echo "obase=20; 40" | bc – Jeff Schaller Jul 12 '17 at 18:45
  • So, it is a space separated decimal numbers for each digit ? – Palash Kanti Kundu Jul 12 '17 at 18:50
  • It wouldn't have been particularly difficult for you to try this out yourself. – roaima Nov 25 '18 at 17:20
1

Yes, bc can process numbers with bases up to 999.

As an example:

$ echo "ibase=10;obase=40;3*40^2+7" | bc
03 00 07

Or, as it should be "307" = 3*40^2 + 0*40^1 + 7*40^0. Or 4807 in decimal.

$  echo "ibase=10;obase=10;3*40^2+7" | bc
4807

So, the values are printed as a two digit (decimal) number with an space as separator.
Some other example:

$ echo "ibase=10;obase=530;371*530^9+222*530^3+127" | bc
371 000 000 000 000 000 222 000 000 127

Or, maybe (in bash), the same number:

$ bc <<<"obase=530;1224212292558591376050694127"
371 000 000 000 000 000 222 000 000 127
6

This is covered in the manual page for bc:

For bases greater than 16, bc uses a multi-character digit method of printing the numbers where each higher base digit is printed as a base 10 number. The multi-character digits are separated by spaces. Each digit contains the number of characters required to represent the base ten value of "obase-1".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.