[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

[Solved] javascript Perl pack [closed]

pack ‘C’, pack ‘N’ and pack ‘H*’ are used to create a sequence of bytes. my $bytes = pack(‘C’, $uint8); # Array of bytes var bytes = []; bytes.push(uint8); # String of bytes var bytes = “”; bytes += String.fromCharCode(uint8); my $bytes = pack(‘N’, $uint32); # Array of bytes var bytes = []; bytes.push((uint32 >> … Read more