예제 #1
0
        /// <summary>
        /// Get the bytes of this IBitWindow as though the bits in the window were a single N-bit integer with a layout that matches
        /// that of the current processor.
        /// Currently restricted to 1,2,4, and 8 byte sized integers.
        /// Currently restricted to unsigned or 2's complement format.
        /// </summary>
        /// <param name="this"></param>
        /// <param name="integerSize">The byte width of the resulting integer.</param>
        /// <param name="signed">Whether or not the resulting integer is signed.</param>
        /// <returns></returns>
        public static Byte[] Crystalize(this IBitWindow @this, IntegerFormat format)
        {
            if (@this == null)
            {
                throw new ArgumentNullException(nameof(@this));
            }
            if (!SupportedIntegerFormats.Contains(format))
            {
                throw new NotSupportedException();
            }

            if (format.BitWidth / 8 < (@this.Length + 7) / 8)
            {
                throw new InvalidOperationException();
            }
            Byte[]    integerBuffer = new Byte[format.BitWidth / 8];
            BitWindow integerView   = new BitWindow(integerBuffer, new EndianBitIndexer(format.ByteOrder, format.BitOrder));

            @this.WriteTo(integerView, 0, 0, @this.Length);
            if (format.Signed)
            {
                if (@this[@this.Length - 1])
                {
                    for (int bitPow = @this.Length; bitPow < integerView.Length; bitPow++)
                    {
                        integerView[bitPow] = true;
                    }
                }
            }
            return(integerBuffer);
        }
예제 #2
0
        public static void ReadFrom(this IBitWindow view, Byte[] src, Int32 srcOffset, Int32 dstOffset, Int32 length, IBitIndexer indexer)
        {
            IBitWindow srcWindow = new BitWindow(src, indexer);

            view.ReadFrom(srcWindow, srcOffset, dstOffset, length);
        }
예제 #3
0
        public static void WriteTo(this IBitWindow view, Byte[] dst, Int32 srcOffset, Int32 dstOffset, Int32 length, IBitIndexer indexer)
        {
            IBitWindow dstWindow = new BitWindow(dst, indexer);

            view.WriteTo(dstWindow, srcOffset, dstOffset, length);
        }