For some reason, obase variable should be defined first and then ibase

specifically, because you told it to output in base twenty-two.

ibase=16; # set the input base to hexadecimal. # all numerical inputs will be treated with an # implied 0x prefix obase=16; # 16 is implied hexadecimal 0x16 = sixteen plus six = twe +nty-two (A5A5A5A5A5A5A5A5/8); # divide 0xA5... by 0x8, and output in base t +wenty-two

And my copy of the bc manpage explains "For bases 2 through 16, the usual method of writing numbers is used. 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. ..."

Sanity check: you expected 0x14b4b4b4b4b4b4b4, which is about (0x14) * 16**14, plus some change: 20 * 16**14 = 1.44e18, plus. You got "05 06 01 09 10 06 00 00 05 16 14 07 14 20", which is about 05 * 22**13, plus some change: 1.41e18, plus. Yep, the output was in base-22.


In reply to Re^3: bc within perl by pryrt
in thread bc within perl by amudelkaa

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.