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.

有帮助吗?

解决方案

works for me :

  print  oct "0b11111";
  31
  print ord(pack("b*","11111"));
  31
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top