This is the as_hex() function from Activestate 5.8.0 (which is actually different from the one currently in CPAN):

sub as_hex { # return as hex string, with prefixed 0x my $x = shift; $x = $class->new($x) if !ref($x); return $x->bstr() if $x->{sign} !~ /^[+-]$/; # inf, nan etc return '0x0' if $x->is_zero(); my $es = ''; my $s = ''; $s = $x->{sign} if $x->{sign} eq '-'; if ($CALC->can('_as_hex')) { $es = ${$CALC->_as_hex($x->{value})}; } else { my $x1 = $x->copy()->babs(); my ($xr,$x10000,$h); if ($] >= 5.006) { $x10000 = Math::BigInt->new (0x10000); $h = 'h4'; } else { $x10000 = Math::BigInt->new (0x1000); $h = 'h3'; } while (!$x1->is_zero()) { ($x1, $xr) = bdiv($x1,$x10000); $es .= unpack($h,pack('v',$xr->numify())); } $es = reverse $es; $es =~ s/^[0]+//; # strip leading zeros $s .= '0x'; } $s . $es; }

In reply to Re^7: Big Int to hex with 5.6 by fglock
in thread Big Int to hex with 5.6 by ZlR

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.