Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^7: Big Int to hex with 5.6

by fglock (Vicar)
on Dec 13, 2004 at 04:06 UTC ( [id://414306]=note: print w/replies, xml ) Need Help??


in reply to Re^6: Big Int to hex with 5.6
in thread Big Int to hex with 5.6

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; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://414306]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-04-18 23:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found