Example #1
0
 /// <summary>
 ///     Overloaded.
 ///     Assembles an integer from specified bits.
 /// </summary>
 /// <param name="H">First Byte</param>
 /// <param name="HU">Upper Index of the First Byte (7-0)</param>
 /// <param name="HL">Lower Index of the First Byte (7-0)</param>
 /// <returns>Integer resulting from contacting all the bits from high to low.</returns>
 public static Int32 ComposeBits(Byte H, Int32 HU, Int32 HL)
 {
     return H.Bits(HU, HL);
 }
Example #2
0
        /// <summary>
        ///     Overloaded.
        ///     Assembles an integer from specified bits.
        /// </summary>
        /// <param name="H">First Byte</param>
        /// <param name="HU">Upper Index of the First Byte (7-0)</param>
        /// <param name="HL">Lower Index of the First Byte (7-0)</param>
        /// <param name="S">Second Byte</param>
        /// <param name="SU">Upper Index of the Second Byte (7-0)</param>
        /// <param name="SL">Lower Index of the Second Byte (7-0)</param>
        /// <returns>Integer resulting from contacting all the bits from high to low.</returns>
        public static Int32 ComposeBits(Byte H, Int32 HU, Int32 HL,
            Byte S, Int32 SU, Int32 SL)
        {
            Int32 Hp = H.Bits(HU, HL);
            Int32 Sp = S.Bits(SU, SL);

            return Hp.SAL(SU - SL + 1) | Sp;
        }
Example #3
0
 // Unsigned
 /// <summary>
 ///     Pads a non standard unsigned integer to 8 bit.
 /// </summary>
 /// <param name="dat">Byte containing non standard integer</param>
 /// <param name="width">Width of the non standard integer</param>
 /// <returns></returns>
 public static Byte PadU8(Byte dat, Int32 width)
 {
     return dat.Bits(width - 1, 0);
 }
Example #4
0
        /// <summary>
        ///     Overloaded.
        ///     Assembles an integer from specified bits.
        /// </summary>
        /// <param name="H">First Byte</param>
        /// <param name="HU">Upper Index of the First Byte (7-0)</param>
        /// <param name="HL">Lower Index of the First Byte (7-0)</param>
        /// <param name="S">Second Byte</param>
        /// <param name="SU">Upper Index of the Second Byte (7-0)</param>
        /// <param name="SL">Lower Index of the Second Byte (7-0)</param>
        /// <param name="T">Third Byte</param>
        /// <param name="TU">Upper Index of the Third Byte (7-0)</param>
        /// <param name="TL">Lower Index of the Third Byte (7-0)</param>
        /// <returns>Integer resulting from contacting all the bits from high to low.</returns>
        public static Int32 ComposeBits(Byte H, Int32 HU, Int32 HL,
            Byte S, Int32 SU, Int32 SL,
            Byte T, Int32 TU, Int32 TL)
        {
            Int32 Hp = H.Bits(HU, HL);
            Int32 Sp = S.Bits(SU, SL);
            Int32 Tp = T.Bits(TU, TL);

            return Hp.SAL(SU - SL + 1 + TU - TL + 1) | Sp.SAL(TU - TL + 1) | Tp;
        }
Example #5
0
        // Signed
        /// <summary>
        ///     Pads a non standard signed integer to 8 bit.
        /// </summary>
        /// <param name="dat">Byte containing non standard integer</param>
        /// <param name="width">Width of the non standard integer</param>
        /// <returns></returns>
        public static SByte PadS8(Byte dat, Int32 width)
        {
            // Assuming that highest bit is sign bit
            Boolean sign = (dat & (1 << width - 1)) != 0;
            Byte value = dat.Bits(width - 2, 0);

            // if the value is negative...
            if (sign) return (SByte) (value - (Byte) Math.Pow(2, width - 1)); // Get 2's complement of the value

            // if it is positive, return value
            return (SByte) value;
        }