On 2020-02-05 20:12, Paul Procacci wrote:
I wasn't going to follow up but decided to do so since there is a small but subtle bug in my original post.
I wouldn't want to mislead you Todd.

The \d has been changed to [0..9] as the expected input would only ever be in that range.  (\d includes Unicode Characters) I've also included an alignment parameter (shadow'ing the sub written by you Todd).

sub sbprint( Int $n, Int :$alignment = 8) {
        my Int $padding = $alignment + $n.msb - ( $n.msb +& ( $alignment  - 1 ) );         '0b' ~ "\%0{$padding}b".sprintf($n).comb(/<[0..9]> ** { $alignment }/).join('_')
}

say sbprint 0x04F842;
say sbprint 0x04F842, :alignment(4);

# ./test.pl6
0b00000100_11111000_01000010
0b0100_1111_1000_0100_0010


`Int :$alignment = 8` was inspired!

What does the ":" do before `alignment`?

Reply via email to