[Solved] perl quick switch from quaternary to decimal
Base 4 requires exactly 2 bits, so it’s easy to handle efficiently. my $uvsize = length(pack(‘J>’, 0)) * 8; my %base4to2 = map { $_ => sprintf(‘%2b’, $_) } 0..3; sub base4to10 { my ($s) = @_; $s =~ s/(.)/$base4to2{$1}/sg; $s = substr((“0” x $uvsize) . $s, -$uvsize); return unpack(‘J>’, pack(‘B*’, $s)); } This allows … Read more