Search code examples
perlpack

Is it possible to pack 5 bits in perl?


For example, let's say I want to pack the following bits: 11111 which is 31 in decimal. How can I pack these 5 bits? I don't want to pack 8 bits or 1 byte. I need to pack only 5 bits; 11111

b5 "11111" doesn't seem to work for me.


Solution

  • works for me :

      print  oct "0b11111";
      31
      print ord(pack("b*","11111"));
      31