4 title => 'number bases',
7 "Cheat sheets summarising various software programs and standards.",
10 sheet cheat reference software overview summary help keyboard map unicode
12 stylesheet => [qw'light dark circus mono red'],
15 my @cols = (2, 6, 8, 9, 10, 12, 16, 18, 20);
16 my @morecols = (2, 3, 4, 6, 8, 9, 10, 12, 16, 18, 20, 24, 32, 36, 64);
17 my @char = (0..9, 'A'..'Z', 'a'..'z');
25 print '<th>', $_ for @cols;
30 my $places = $count<<1;
33 my ($num, $radix) = @_;
40 for my $place (1 .. $places) {
41 # add a digit in requested base (left shift)
42 $out .= $char[ $num->blsft(1, $radix) ];
44 # no remaining fractional part
45 $class = $out eq '1' ? 'l5' : $place == 1 ? 'l4' : 'l3';
48 $zeros++ if $out =~ /^0+$/;
50 for my $check ($zeros .. length($out)>>1) {
51 if (substr($out, -$check) eq substr($out, -$check*2, $check)) {
52 $class = $check == 1 ? 'l2' : 'l1';
53 substr($out, -$check) = '';
54 substr($out, -$check, 0) = '<span style="text-decoration:overline">';
60 printf '<td%s style="text-align:left">%s', $class && qq( class="$class"), $out;
63 for my $n (2 .. $count) {
66 for my $radix (@cols) {
67 my $accuracy = int($places * log($radix) / log(10));
68 Math::BigFloat->accuracy($accuracy);
69 showfrac(scalar Math::BigFloat->new(1)->bdiv($n, $accuracy+1), $radix);
82 my ($int, $radix) = @_;
85 push @digits, $char[$int % $radix];
88 splice @digits, 3 * $_, 0, ' ' for reverse 1 .. @digits/3;
89 return join '', reverse @digits;
92 @cols = grep { not $_ ~~ [2,8,16] } @cols, 36;
94 print '<th>', $_ for @cols;
96 for my $n (3 .. 16, 18, 20, 24, 30, 32, 36, 40, 48, 50, 60, 64) {
99 for my $radix (@cols) {
100 print '<td style="text-align:right">', showint(2 ** $n, $radix);