laziness, impatience, and hubris 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??

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.

Create A New User
Node Status?
node history
Node Type: note [id://849296]
help
Chatterbox?
 [erix]: Harakiri with a nuke on the white house, that'd clean up the staff there a bit too ;) [erix]: (sorry, I'm always a bit violent on fridays) LanX predicts problems for Erix next time he lines up at an US immigration counter [erix]: thanks for the heads-up but that's a line-up studiiously avoided :P

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (11)
As of 2017-08-18 13:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Who is your favorite scientist and why?

Results (302 votes). Check out past polls.

Notices?