Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
base N conversion
#perl 5.22.1 #Challenge 42-1 # represent one decimal integer in another base # use feature 'say'; my $base=8; # Allows bases from 2..36 for (1..50){ say "Decimal $_ is ", baseN($base,$_), " in base $base" ; } sub baseN{ my $base=shift; my $number=shift; my @digits=(0..9,A..Z); # potential output characters my $string=""; # holds the output as string of characters while ($number>0){ # continue until no more required my $remainder=$number % $base; # get the remainder after division with base $string=$digits[$remainder].$string; # add that to the left most side of string $number=($number-$remainder)/$base; # divide the residual number by base } return $string # return the result }
run
|
edit
|
history
|
help
0
hash of arrays of arrays
Perl
Quote code
array flipper
2
Array_with_shift_function
Prac 2 #2
Array_range_operators
Arrayop
Compare Versions