private static byte[] CreateBytes(BitBuffer buffer, RSBlock[] rsBlocks) { int offset = 0; int maxDcCount = 0; int maxEcCount = 0; int[][] dcdata = new int[rsBlocks.Length][]; int[][] ecdata = new int[rsBlocks.Length][]; for (int r = 0; r < rsBlocks.Length; r++) { int dcCount = rsBlocks[r].GetDataCount(); int ecCount = rsBlocks[r].GetTotalCount() - dcCount; maxDcCount = Math.Max(maxDcCount, dcCount); maxEcCount = Math.Max(maxEcCount, ecCount); dcdata[r] = new int[dcCount]; for (int i = 0; i < dcdata[r].Length; i++) { dcdata[r][i] = 0xff & buffer.GetBuffer()[i + offset]; } offset += dcCount; Polynomial rsPoly = QRUtil.GetErrorCorrectPolynomial(ecCount); Polynomial rawPoly = new Polynomial(dcdata[r], rsPoly.GetLength() - 1); Polynomial modPoly = rawPoly.Mod(rsPoly); ecdata[r] = new int[rsPoly.GetLength() - 1]; for (int i = 0; i < ecdata[r].Length; i++) { int modIndex = i + modPoly.GetLength() - ecdata[r].Length; ecdata[r][i] = (modIndex >= 0)? modPoly.Get(modIndex) : 0; } } int totalCodeCount = 0; for (int i = 0; i < rsBlocks.Length; i++) { totalCodeCount += rsBlocks[i].GetTotalCount(); } byte[] data = new byte[totalCodeCount]; int index = 0; for (int i = 0; i < maxDcCount; i++) { for (int r = 0; r < rsBlocks.Length; r++) { if (i < dcdata[r].Length) { data[index++] = (byte) dcdata[r][i]; } } } for (int i = 0; i < maxEcCount; i++) { for (int r = 0; r < rsBlocks.Length; r++) { if (i < ecdata[r].Length) { data[index++] = (byte) ecdata[r][i]; } } } return data; }