Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
We don't bite newbies here... much
 
PerlMonks  

Re^2: Convert big number from decimal to hexadecimal

by ambrus (Abbot)
on Jul 13, 2010 at 15:01 UTC ( #849296=note: print w/ replies, xml ) Need Help??


in reply to Re: Convert big number from decimal to hexadecimal
in thread Convert big number from decimal to hexadecimal

Okay, here's it a bit shortened:

use 5.010; sub dalu { no warnings "uninitialized"; my($a, $b, $n, $o) = @_; my @b = @$b; my $c = $n && 1; for (my $k = 0; @b || $k < @$a || $c && !$n; $k++) { my $y = shift @b; $n and $y = 9 - $y; $c = 10 <= (my $z = $$a[$k] + $c + $y); $o or $$a[$k] = $z % 10; } $c; } my $n = [reverse split //, "4335043554366887798866555766"]; my $p = [1]; my $e = 0; while (dalu $n, $p, 1, 1) { dalu $p, $p for 0..3; $e++; } my $r; for my $_e (0 .. $e - 1) { dalu $n, $n for 0..3; my $i = 0; while (dalu $n, $p, 1, 1) { dalu $n, $p, 1; $i++; } $r .= sprintf "%x", $i; } say $r; __END__

Update: made code a bit nicer.


Comment on Re^2: Convert big number from decimal to hexadecimal
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2014-04-19 13:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (480 votes), past polls