From: "Aleksi Niemelä" Date: 2000-07-17T14:28:00+02:00 Subject: [ruby-talk:04081] Re: unpack and "bn" with n>16 > is there any way to do what i meant to do? aka > > p ["1", "1", "1","1"].pack("b4b2b1b1") > #-> [ 0b00010111 ].pack("C") > #-> "\027" I guess you can modify the pack.c easily to do successive unpacking (in one pattern, or one call). You have to move the 'bits' initialization to function level and count remaining bits explicitly (i&7 would not return it anymore). case 'b': { VALUE bitstr; char *t; int bits, i; if (p[-1] == '*' || len > (send - s) * 8) len = (send - s) * 8; bits = 0; rb_ary_push(ary, bitstr = rb_str_new(0, len)); t = RSTRING(bitstr)->ptr; for (i=0; i>= 1; else bits = *s++; *t++ = (bits & 1) ? '1' : '0'; } } break; The packing part isn't much harder, but there you have to remember to "flush" the 'bitstore' when successive "bN" entries end. In any case, I suggest that you'd contribute a real patch to matz and name your 'successive b-entries operated upon single byte' -version to some other name than 'b'. I'd also suggest that pack should be left as it is and general class BitHandling should be introduced with enough capabilities to satisfy most cryptographical software etc. needs. It would be proper place for speedy handling of bit packing, unpacking, buffering, counting and different platforms could be hided behind that abstraction so people wouldn't use slow 8-bit bit-routines on 64-bit (or bigger) machines. Maybe you can read it from my answer that I don't know any other easy way than hacking :). One black art, super magic "trick" is yet to be mentioned: you can use Ruby to code the effect you want ;-]. - Aleksi