my $posting; for my $docid(1 .. 20) { $posting. = ByteEncode($docid); } #At the end i pack the whole bit string my $compressed = pack "b*",$posting; # i am not sure if its the best format... #Decode the compressed Bit string my $df = 20; #number of compressed docs.. my $bits=7; my $decode = unpack "b*",$posting; my @w;my $nr=0; my $binary=''; my $start=0; while() { #ckeck the MSB, if it is 1 then its the last byte for the current Docid my $temp = substr($decode,0,$bits+1,''); # its the last one... if($temp=~ m/^1/) { substr($temp,0,1,''); $binary.=$temp; push @w,bin2dec($binary); undef $binary; $nr++; last if($nr==$df); } #else remove the MSB and keep the rest and go to the next byte else { substr($temp,0,1,''); $binary.=$temp; } } return @w;