Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
14
Task/Bitwise-IO/Raku/bitwise-io.raku
Normal file
14
Task/Bitwise-IO/Raku/bitwise-io.raku
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
sub encode-ascii(Str $s) {
|
||||
my @b = flat $s.ords».fmt("%07b")».comb;
|
||||
@b.push(0) until @b %% 8; # padding
|
||||
Buf.new: gather while @b { take reduce * *2+*, (@b.pop for ^8) }
|
||||
}
|
||||
|
||||
sub decode-ascii(Buf $b) {
|
||||
my @b = flat $b.list».fmt("%08b")».comb;
|
||||
@b.shift until @b %% 7; # remove padding
|
||||
@b = gather while @b { take reduce * *2+*, (@b.pop for ^7) }
|
||||
return [~] @b».chr;
|
||||
}
|
||||
say my $encode = encode-ascii 'STRING';
|
||||
say decode-ascii $encode;
|
||||
Loading…
Add table
Add a link
Reference in a new issue