CanvasBin.CanvasBin.IntermediateData.Convert C# (CSharp) Method

Convert() private static method

private static Convert ( byte[]>.Dictionary alignments, int>.Dictionary bitsInLastByteAlignments ) : BitArray>.Dictionary
alignments byte[]>.Dictionary
bitsInLastByteAlignments int>.Dictionary
return BitArray>.Dictionary
            private static Dictionary<string, BitArray> Convert(Dictionary<string, byte[]> alignments,
                Dictionary<string, int> bitsInLastByteAlignments)
            {
                Dictionary<string, BitArray> tempAlignments = new Dictionary<string, BitArray>();
                foreach (KeyValuePair<string, byte[]> kvp in alignments)
                {
                    int numberBitsInLastByte = bitsInLastByteAlignments[kvp.Key];
                    BitArray bits = null;
                    if (numberBitsInLastByte > 0)
                    {
                        int numBitsFromFullBytes = 8 * (kvp.Value.Length - 1);
                        bits = new BitArray(numBitsFromFullBytes + numberBitsInLastByte);
                        BitArrayCopyFrom(bits, kvp.Value, numBitsFromFullBytes);
                        byte lastByte = kvp.Value[kvp.Value.Length - 1];
                        for (int bitIndexLastByte = 0; bitIndexLastByte < numberBitsInLastByte; bitIndexLastByte++)
                        {
                            bool bit = (lastByte & (1 << bitIndexLastByte)) != 0;
                            bits.Set(numBitsFromFullBytes + bitIndexLastByte, bit);
                        }
                    }
                    else
                    {
                        bits = new BitArray(kvp.Value);
                    }

                    tempAlignments[kvp.Key] = bits;
                }
                return tempAlignments;
            }