Esempio n. 1
0
        /// <summary>
        /// Initializes the bit string.
        /// </summary>
        /// <param name="discreteSpaceDescriptor">The discrete space descriptor.</param>
        /// <returns>BitByteHexLimits[].</returns>
        internal static BitByteHexLimits[] InitializeBitString(DesignSpaceDescription discreteSpaceDescriptor)
        {
            var result       = new BitByteHexLimits[discreteSpaceDescriptor.n];
            var currentIndex = 0;

            for (var i = 0; i < discreteSpaceDescriptor.n; i++)
            {
                if (discreteSpaceDescriptor[i].Discrete)
                {
                    var maxValue   = discreteSpaceDescriptor.MaxVariableSizes[i];
                    var numberBits = (int)(Math.Log(maxValue, 2)) + 1;
                    var endIndex   = currentIndex + numberBits;
                    result[i] = new BitByteHexLimits
                    {
                        StartIndex = currentIndex,
                        EndIndex   = endIndex,
                        MaxValue   = maxValue
                    };
                    currentIndex = endIndex;
                }
                else
                {
                    result[i] = new BitByteHexLimits();
                }
            }
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Flips the bit.
        /// </summary>
        /// <param name="initValue">The initialize value.</param>
        /// <param name="limits">The limits.</param>
        /// <param name="bitIndex">Index of the bit.</param>
        /// <returns>System.Int64.</returns>
        internal static long FlipBit(long initValue, BitByteHexLimits limits, int bitIndex)
        {
            bitIndex -= limits.StartIndex;
            var b = Encode(initValue, limits.EndIndex - limits.StartIndex);

            b.Set(bitIndex, !b[bitIndex]);
            return(Decode(b, limits.MaxValue));
        }