From: "Aleksi Niemelä" Date: 2000-07-17T13:45:47+02:00 Subject: [ruby-talk:04077] RE: unpack and "bn" with n>16 Pixel: > p "\0\0\0\0".unpack("b16b1b2") # -> ["0000000000000000", "0", "00"] > p "\0\0\0\0".unpack("b17b1b1") # -> ["00000000000000000", "0", ""] > > I can't find it though :( String#unpack("bX") where X is bits between 1-8 eat the first byte. When X is between 9-16 it eats the second byte too (and actually access the first bits and discards ie. doesn't process the rest). So "b16" is eating the first two zero bytes, and "b1" the first bit of the third byte (and consumes the whole bytes), and the "b2" in the end accesses the last of "\0"s. Where as the second line consumes first three bytes with "b17", and the last byte with "b1" and the last "b1" doesn't have any input to eat. I guess you're expecting the successive "b1b2b3b2" to consume only one byte whereas it eats the four. - Aleksi