Exemplo n.º 1
0
        /// <summary>
        ///     Pads a non standard signed integer to 16 bit.
        /// </summary>
        /// <param name="dat">UInt16 containing non standard integer</param>
        /// <param name="width">Width of the non standard integer</param>
        /// <returns></returns>
        public static Int16 PadS16(UInt16 dat, Int32 width)
        {
            // Assuming that highest bit is sign bit
            Boolean sign = (dat & (1 << width - 1)) != 0;
            UInt16 value = dat.Bits(width - 2, 0);

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

            // if it is positive, return value
            return (Int16) value;
        }
Exemplo n.º 2
0
 /// <summary>
 ///     Pads a non standard unsigned integer to 16 bit.
 /// </summary>
 /// <param name="dat">UInt16 containing non standard integer</param>
 /// <param name="width">Width of the non standard integer</param>
 /// <returns></returns>
 public static UInt16 PadU16(UInt16 dat, Int32 width)
 {
     return dat.Bits(width - 1, 0);
 }