Is it possible to pack 5 bits in perl?

129 views Asked by At

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.

1

There are 1 answers

0
michael501 On BEST ANSWER

works for me :

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