private static BitArray CompressPostingList(int[] posList) { var bitsArrays = new BitArray[posList.Length]; for (int i = 0; i < posList.Length; i++) { var binary = new List<int>(); while (posList[i] != 0) { binary.Add(posList[i]%2); posList[i] /= 2; } binary.Reverse(); if (binary.Count != 0) { bitsArrays[i] = new BitArray(binary.Count*2 - 1); for (int j = 0; j < binary.Count - 1; j++) { bitsArrays[i][j] = true; } bitsArrays[i][binary.Count - 1] = false; for (int j = 1; j < binary.Count; j++) { bitsArrays[i][j + binary.Count - 1] = binary[j] == 1; } } } int resultLength = bitsArrays.Select(n => n.Length).Sum(); var result = new BitArray(resultLength); int k = 0; for (int i = 0; i < bitsArrays.Length; i++) { for (int j = 0; j < bitsArrays[i].Length; j++) { result[k++] = bitsArrays[i][j]; } } return result; }