Home > other >  What does pack("B*", $s) do In Perl?
What does pack("B*", $s) do In Perl?

Time:03-08

I am migrating some perl code to python and cant seem to understand what

pack("B*", $s)

does in perl.

Is there an equivalent in Python?

CodePudding user response:

pack:

B A bit string (descending bit order inside each byte)

It takes a bit string, and produces the corresponding bytes.

For example, pack "B*", "0100000101000010" is equivalent to "\x41\x42" and chr(65).chr(66).

$ perl -Mv5.10 -e'say sprintf "%vX", pack "B*", "0100000101000010"'
41.42
```
  • Related